I\'m wondering if there is a best way or best practice to get the full path of application in Node.js. Example: I have a a module in sub folder /apps/myapp/data/models/m
This worked for me.. With supervisor running the app from a different dir.
require('path').dirname(Object.keys(require.cache)[0])
example.. files: /desktop/ya/node.js
require('./ya2/submodule')();
/desktop/ya/ya2/submodule.js
module.exports = function(){
console.log(require('path').dirname(Object.keys(require.cache)[0]))
}
$ node node.js
=> /desktop/ya
$ (from /desktop) supervisor ya/node.js
=> /desktop/ya