How do I require a module using node from the command line?

You can execute the following:

npm install moment # module must be installed locally
node --require moment

And enter the following:

var moment = require('moment');
moment().format();

From the man page:

-r, --require          module to preload at startup

According to the source, it appears that node --require will not search for global modules in version 4.2.x and will not raise any errors if the module is installed globally and not locally.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)