How can I make require look in the relative path of the executing script (not whatever script has require'd the executing script)? Example:
index.js
require('lib/foo.js');
--
lib/foo.js
var barFunction = require('./bar.js').barFunction;
barFunction();
--
lib/bar.js
module.exports.barFunction = function(){
return true;
}
When you node index.js, foo.js looks for bar.js instead of lib/bar.js.
If foo.js is amended to require('lib/bar.js'), then node foo.js will stop working.
How can I set up require in a way that I can both node index.js and node lib/foo.js and have then both work?
./lib/foo.jsinstead oflib/foo.js? Other than that, there isn't anything wrong with your code.node foo.jsdirectly in the lib folder. I need that to work as well.