Node.js - how to set environment variables in code
You can not only consume environment variables in node with process.env
but also set them. This will set the variable within your current node process and any child processes it calls, but not the calling shell itself.
// consumevar alreadySetEnvVarForDevice = process.env.NOBLE_HCI_DEVICE_ID// setprocess.env['NOBLE_HCI_DEVICE_ID'] = 1
If you are using express, you can set the variables as follow:
var express = require('express');var app = express();// set the environment mode, default is process.env.NODE_ENVapp.set('env','development');app.get('env');// => 'development'
run command like following in command prompt
export FOREVER_ROOT=/var/log/
Here export set a environment variable
OR
Execute "/etc/environment" in every shell where you want the variables to be updated:
$ /etc/environment