Last active
March 25, 2025 13:10
-
-
Save antonlvovych/e2e3e0325abd9023d3a3 to your computer and use it in GitHub Desktop.
Get root path of node.js application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
module.exports = (function () { | |
return path.dirname(require.main.filename || process.mainModule.filename); | |
})(); | |
// Example of usage: | |
var root = require('root'); // In root will be absolute path to your application |
Very useful! Thanks a lot
this is not working
Hey @glarivie try this path.resolve(process.cwd(), 'your filename in root folder')
This function gives only root folder of current file not root of application.
Use process.cwd()
There are all kinds of problems with this, see: https://stackoverflow.com/questions/10265798/determine-project-root-from-a-running-node-js-application
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful!! Thanks