There are two main ways to reference the current directory in nodejs.
|__dirname||Current path of the js file being executed.|
|process.cwd()||Current working directory at runtime.|
The sample codes are below:
console.log("running now on : " + __dirname); console.log("exec from : " + process.cwd());
Try to run this in a shell (command prompt) from a different path. The execution result is as follows:
> pwd /home/amaji/ <-- Check Current Working Directory! > node /home/sample/sample.js running now on : /home/sample/ exec from : /home/amaji/
That's all! That was from my memo!
Thank you for your message.
Sorry. The Error has occurred.We apologize for the inconvenience.Please try again in a few minutes or contact us via DM below.Twitter:@NodachiSoft_engName:
Send the following information to us. If you are happy with your submission, please click "Send". If you want to modify it, please click "Back".Name: