I have a javascript file that is normally used in a web browser using a script tag. It is a self-executing function that seems to put an object on the window (the window is passed in).
What would be the cleanest way to use it from node.js on the server?
Thanks,
Gareth
If all it does is add attributes to
window, and you want to get those back out, you can create a global calledwindow:However, if the library was written for the browser, it’s possible that it still won’t run because it wants to use the DOM. In that case, you might want to look into jsdom, which aims to give you a spec-compliant DOM inside Node.
(If you’re using jsdom, I think that you would use it instead of the
global.windowbit above — I think jsdom does that for you, but with a more full-featured window object. I haven’t actually used jsdom, though, so I don’t know for sure.)