Node.js global variables


I asked here:
Does Node.js require inheritance?

And I was told that I can set variables to the global scope by leaving out the variable.

This does not work for me.

That is, the following does not make the _ available on required files.

_ = require('underscore');

I can set with Express.js’s app.set and have it available elsewhere though.

Is that how this is supposed to work?


You can use global like so:

global._ = require('underscore')

Answered By – masylum

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.