Simple ways to determine root path of your node.js applications:
- Add this somewhere towards the start of your main app file: app.js
global.__basedir = __dirname;
Use it just like any other global variables:
folderPath = __basedir + '/storage/data.json';
// or
const userModule = require(__basedir + '/modules/user.module.js');
- NodeJS.Process.cwd():
const process = require('process');
...
const __basedir = process.cwd();
const userModule = require(__basedir + '/modules/user.module.js');
Be First to Comment