3
I am learning Nodejs and I started to create a project just to get used to developing with him, however, I am bothered by the amount of ../../../../../
used when including a code. How can I use my application’s root folder as path reference?
3
I am learning Nodejs and I started to create a project just to get used to developing with him, however, I am bothered by the amount of ../../../../../
used when including a code. How can I use my application’s root folder as path reference?
4
__dirname
This gives you the currently running file path
__filename
This is the absolute path of the current module file
example
console.log(__filename);
// Prints: /Users/mjr/example.js
console.log(__dirname);
// Prints: /Users/mjr
Browser other questions tagged javascript node.js
You are not signed in. Login or sign up in order to post.
It doesn’t solve my problem, I wanted some way to use the root folder of my project.
– Wesley Nascimento
already tried var appRoot = require('app-root-path'); var myModule = require(appRoot + '/lib/my-module.js');
– Eduardo Sampaio
I managed to find a way here, thanks.
– Wesley Nascimento