I am writing a Node.js express application and want to use environment variables to set the port on which the server should run.
However, I cannot get process.env.PORTto read my environment variable PORT.
I defined the PORT environment variable using the exportfollowing:
export PORT=1234I also added this line to the file ~/.bash_profile, but process.env.PORTremains undefined.
When I run echo $PORTin the terminal, it displays the value ( 1234) correctly .
I am running Node V0.12.7 and OSX El Capitan 10.11.1 and really can't find any further hints about what might be causing this.
Thanks!
EDIT:
Here is the code executed before trying to assign to a process.env.PORTvariablePORT
var app = require('../app');
var proxy = require("../proxy");
var http = require('http');
var nconf = require('nconf');
nconf.file(__dirname + "/appConf.json");
var appSettings = require('../appSettings');
var port = normalizePort(process.env.PORT || 8080);
source
share