Both "return the current working directory of the process".
It seems you can override the value of process.env.PWD
but it will not change the returning value of process.cwd()
.
process. env. PWD is the working directory when the process was started. This stays the same for the entire process.
The process.env property is an inbuilt application programming interface of the process module which is used to get the user environment. Syntax: process.env. Return Value: This property returns an object containing the user environment.
__dirname: It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file.
The pwd command will return the current working directory.
PWD
is the current working directory when the process is started, but it is constant. process.cwd()
is asking the underlying system for the process's current directory, which can be changed with process.chdir()
. PWD
is also a POSIX environmental variable, which means it won't work on Windows. process.cwd()
on the other hand, will.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With