Node.js · Junior · Question 51 of 75

What is the difference between process.cwd() and __dirname?

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.

Further reading

Problem with a question

Node.js · Junior · question 51

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz