In this article, we would like to show you how to get current directory in Node.js.
const currentDirectory = __dirname;
const currentDirectory = process.cwd();
In this example, we create two variables for the current working directory using two different methods.
const currentDirectory1 = __dirname; const currentDirectory2 = process.cwd(); console.log(currentDirectory1); // C:\projects\app console.log(currentDirectory2); // C:\projects\app