Both these require statements appear to work the same way:
require
var Mypackage = require('mypackage.js');
var Mypackage require('mypackage');
Is there a difference between them?
Here is the answer:
Module.prototype.load = function(filename) { debug('load ' + JSON.stringify(filename) + ' for module ' + JSON.stringify(this.id)); assert(!this.loaded); this.filename = filename; this.paths = Module._nodeModulePaths(path.dirname(filename)); var extension = path.extname(filename) || '.js'; if (!Module._extensions[extension]) extension = '.js'; Module._extensions[extension](this, filename); this.loaded = true; };
http
fs
node_modules
utils
./node_modules/utils.js
./node_modules/utils/index.js
./node_modules/utils/package.json
NODE_PATH
Error:
Cannot find module 'yourfile'
2.1m questions
2.1m answers
60 comments
57.0k users