Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between process.cwd() vs process.env.PWD?

Tags:

node.js

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().

like image 618
beatak Avatar asked Jun 22 '15 23:06

beatak


People also ask

What is process ENV PWD?

process. env. PWD is the working directory when the process was started. This stays the same for the entire process.

What means process ENV?

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.

What is __ Dirname in node?

__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.

Which method returns the current working directory of the process?

The pwd command will return the current working directory.


1 Answers

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.

like image 61
loganfsmyth Avatar answered Oct 17 '22 12:10

loganfsmyth