Languages
[Edit]
EN

Node.js - get current directory

0 points
Created by:
p_agon
409

In this article, we would like to show you how to get current directory in Node.js.

Quick solution:

const currentDirectory = __dirname;

or:

const currentDirectory = process.cwd();

 

Practical example

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

Output:

C:\projects\app
C:\projects\app
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join