Node.js · Junior · Question 51 of 75
What is the difference between process.cwd() and __dirname?
- 1They are always the same
- ✓Correct answer:
process.cwd()is the directory where Node.js was started;__dirnameis the folder of the current file - 3
process.cwd()is the user's home directory
Explanation
If you run node src/app.js from the project root, cwd is the root and __dirname is src. To load files next to the code, build paths from __dirname or import.meta.dirname.