Solved: start by typing node and pressing enter, then type process. env and press enter.
Accessing NODE_ENV: We can access NODE_ENV like any other environment variable using process and env of NodeJS as we have already seen while learning about environment variables. We can write environment-specific code by checking the value of NODE_ENV by using process. env. NODE_ENV.
Node. js exposes the current process's environment variables to the script as an object called process. env. From there, the Express web server framework popularized using an environment variable called NODE_ENV as a flag to indicate whether the server should be running in “development” mode vs “production” mode.
You can access it from process. env. NODE_ENV . This variable changes based on what mode you are currently in.
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.
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
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.
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.
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.
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