Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Node.js · Pipe

process.cwd

process.cwd() returns the current working directory of the Node.js process as a string. It takes no arguments.

Since
v0.1.8

How it works

Call process.cwd() to obtain the Node.js process's current working directory as a string. It reports the process location used for resolving relative paths, not the directory containing the current module.

Syntax

process.cwd(): string

Returns

string containing the current working directory of the Node.js process

Key points

  • Calling process.cwd() reads the directory currently assigned to the running Node.js process.
  • The method accepts no arguments and produces a string path.
  • Node.js introduced this API in version 0.1.8.
  • The returned path can be interpolated into output or passed to other APIs that accept filesystem paths.

Common mistakes

  • Do not confuse the process working directory with the location of the current source file; they can differ.

Example: Read the process working directory

console.log(`Current directory: ${process.cwd()}`);

Prints the directory from which the Node.js process is currently running.

When to use it

Build process-relative filesystem paths

Resolve a relative path against the directory from which the application was launched.

Inspect runtime location

Log startup context when diagnosing deployment or command-line execution issues.

Locate CLI inputs

Choose files relative to the process launch directory in a CLI tool.

Interview questions

QWhat does process.cwd() return?

process.cwd() takes no arguments and returns a string containing the Node.js process's current working directory. It is available through the global process object.

Follow-up: How can the process working directory change? process.chdir(directory) changes it when the target directory is valid; otherwise it throws.

QWhat does the returned path represent?

It returns the working directory associated with the running process, which is the base commonly used for relative filesystem paths. The result is a string.

Follow-up: How would you get a module's directory instead? Use module-system-specific metadata such as import.meta.url rather than treating process.cwd() as the module location.

QWhat is its signature and when was it added?

The method has the declaration process.cwd(): string; it accepts no parameters and returns the current working directory. The documentation lists it as added in Node.js v0.1.8.

Follow-up: What operation changes the value returned by this method? Calling process.chdir() changes the process's current working directory.

  • process.chdir
  • process
  • import.meta.url

Source: process.cwd | Node.js 26.8.1 Documentation. Checked 2026-10-15.