I have:
- added export NODE_ENV=production to app-root/data/.bashprofile (and echo $NODE_ENV shows production)
- Tried rhc set-env NODE_ENV=production -a myapp which generates Setting environment variable(s) ... Server returned an unexpected error code: 501
- Created an .openshift/action_hooks directory in my local repo and added the line export NODE_ENV=production to both a start and a pre_start file, committed and pushed to openshift
- Tried the .openshift/action_hooks/pre_start_* aswell
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?
UPDATE
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);