How can I make Node.js ‘require’ absolute? (instead of relative)

Use:

var myModule = require.main.require('./path/to/module');

It requires the file as if it were required from the main JavaScript file, so it works pretty well as long as your main JavaScript file is at the root of your project… and that’s something I appreciate.

Leave a Comment