Inside the "module.js" trick uses module.parent. filename
I personally do not like to use global variables, and for certain files (for example, configuration or templates), managing the module requires that the stack be not so difficult.
module.parent maps to the parent module (which may be app.js, as in your example).
By combining module.parent.filename with a path module, you get a few useful things, such as:
var path = require('path'); var parent_path = path.dirname(module.parent.filename); var parent_relative = path.resolve(path.join(parent_path, '../', 'view')); var template = path.join(parent_path,'./views/template.html');
I don't like using global variables for anything related to paths, I get spagetti ../../../dir./s
electblake
source share