ReferenceError : window is not defined at object. Node.js

window is a browser thing that doesn’t exist on Node.

If you really want to create a global, use global instead:

global.windowVar = /*...*/; // BUT PLEASE DON'T DO THIS, keep reading

global is Node’s identifier for the global object, like window is on browsers.

But, there’s no need to create truly global variables in Node programs. Instead, just create a module global:

var windowVar = /*...*/;

…and since you include it in your exports, other modules can access the object it refers to as necessary.

Leave a Comment