I have:
Declared a root variable (as tipsed by @JuJoDi below) in the beginning of my server.js file, now it looks lite this:
var express = require('express'),
routes = require('./routes'),
api = require('./routes/api'),
http = require('http'),
path = require('path'),
everyauth = require('everyauth'),
connect = require('connect'),
env = process.env.NODE_ENV ? process.env.NODE_ENV : "process.env.NODE_ENV is null";
I'm then printing out using this route:
app.get('/version', function(req,res){
res.json({
"app.get('env')" : app.get('env'),
"process.env.NODE_ENV" : process.env.NODE_ENV,
"Global env" : env
});
});
What happens is that app.get('env') always returns 'development' and process.env.NODE_ENV is not printed at all (null value)
Has anyone got any ideas why this isn't working?
I created a minimalistic node server, still can't get any env-variables to work on open shift:
var http = require('http');
var port = process.env.OPENSHIFT_NODEJS_PORT || 3000;
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || process.env.OPENSHIFT_INTERNAL_IP || 'localhost';
var env = process.env.NODE_ENV
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('' + process.env.NODE_ENV + "|" + env);
}).listen(port, ipaddress);
I couldn't reproduce this issue. I think the 501 error response that you initially received is the cause of your problems.
You should be able to troubleshoot by running the following from within in your project source folder (add -a YOUR_APP_NAME
to the end of each command to run elsewhere):
Check your current list of application tokens:
rhc env list
If you have something listed for NODE_ENV
, then clear it:
rhc unset NODE_ENV
Set your NODE_ENV
to "production":
rhc env set NODE_ENV="production"
Verify that the value has been set by reloading your server, by running rhc env list
, or by connecting to your application over SSH to check the system environment directly:
rhc ssh
env | grep NODE_ENV
Running rhc help env
provides a lot of good usage info as well. Depending on how they're written, some servers need to be reloaded in order to fetch the new content.
I think the easiest way to get up and running with MEANStack on OpenShift is to use Yeoman's Angular-fullstack generator. It should automatically configure your environment for you.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments