Build process-relative filesystem paths
Resolve a relative path against the directory from which the application was launched.
Node.js · Pipe
process.cwd() returns the current working directory of the Node.js process as a string. It takes no arguments.
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.
process.cwd(): stringstring containing the current working directory of the Node.js process
process.cwd() reads the directory currently assigned to the running Node.js process.console.log(`Current directory: ${process.cwd()}`);Prints the directory from which the Node.js process is currently running.
Resolve a relative path against the directory from which the application was launched.
Log startup context when diagnosing deployment or command-line execution issues.
Choose files relative to the process launch directory in a CLI tool.
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.
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.
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.chdirprocessimport.meta.url