Is there a way to display NODE_ENV from the command line?
node.jsnode.js Problem Overview
Please, answers here all refer to a something called process.env.NODE_ENV, but echo $process.env.NODE_ENV
from the command line did not work. Any ideas?
node.js Solutions
Solution 1 - node.js
Use echo $NODE_ENV
. The command line is a shell, probably bash and that's the bash syntax to print the value of an environment variable.
Solution 2 - node.js
If you have defined NODE_ENV
variable then you should be able to see this by typing node
in the command prompt which will open the node cell and then type process.env.NODE_ENV
.
To check the existing env variables .. type this .. process.env
Solution 3 - node.js
You call list all variables for Macs available for your project directory with...
printenv
I use this often to look for the NODE_ENV and other variables.
Solution 4 - node.js
go to node REPL, and then give process.env.NODE_ENV and the variable process is scoped inside nodejs process, not in your shell process.
sk3037@saravana:~/src$ node
> process.env.
Solution 5 - node.js
Setp-by-step windows CMD NODE_ENV:
-
> set NODE_ENV=my_node_env (defines NODE_ENV)
-
> node (run node)
-
> process.env.NODE_ENV (show NODE_ENV)
After "set NODE_ENV" you can run the application, and it will use the set NODE_ENV. You can run your application with custom environment in pm2 without problem.
Solution 6 - node.js
To display the current node environment in windows, use:
> echo %NODE_ENV%
It wil output the environment on the command line like:
development
Solution 7 - node.js
- Find the Id of the process you are running by executing
ps aux | grep node
- Look at the environment variables used by that process by executing
less /proc/[your-id]/environ
Solution 8 - node.js
Have you set the NODE_ENV for process?
Here are some example.
Somewhere in code, you set the node environment to "production"
or "development"
or "any thing you want"
.
And do some stuff according to your node environment.
process.env.NODE_ENV="production";
//others coding
if(process.env.NODE_ENV === "production")
{
//useblabla log level.
//use production log.
}
else if(process.env.NODE_ENV === "development")
{
//useblabla log level.
//use development log.
}
console.log(process.env.NODE_ENV); //"production"