Can't get NODE_ENV to stick on my MEAN stack on open shift

Joche

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);
ʀɣαɳĵ

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):

  1. Check your current list of application tokens:

    rhc env list

  2. If you have something listed for NODE_ENV, then clear it:

    rhc unset NODE_ENV

  3. Set your NODE_ENV to "production":

    rhc env set NODE_ENV="production"

  4. 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.

edited at
0

Comments

0 comments
Login to comment

Related

Can't understand if my USB stick is buggy

Can't use .env file in vue js while running cross-env NODE_ENV=development webpack-dev-server --open --hot

Can't get footer to stick at bottom of page

Can't get my nav bar to stick to top after scrolling past header?

Why can't I set NODE_ENV to undefined?

Can't set NODE_ENV=production with npm and webpack

Can't Set NODE_ENV to production with webpack

how i can get started with MEAN stack?

Can't seem to get my list view to open from a button

Why can't I write to my USB Stick?

Can't get div to stick to bottom of another div with position: absolute

How can I check if my pm2 app NODE_ENV is getting set?

Can't open grub menu through Shift or Esc keys

Can't download file using res.sendFile() by MEAN Stack

Can't install Bitnami MEAN stack on Windows 10

Can't correctly shift my values on uint64?

Can't get the right alignment using Stack

can't get ggplot bars to stack

Can't get nested div to stack

Can't get my next form to open due to "Error creating Window Handle" error

FileZilla on Mac OS X can't open .ssh directory to get my keyfile

Can't get in my acount

I can't wrap my head around the "draw some stairs with stick-men" program

Can't get Mouse back in gEdit after Shift Key Is Pressed

Can't get private keys for my bitcoin wallet on own node

Why can't I open my file using open method?

Nginx is can't get my env var from my docker compose file

Can't open my site on my laptop anymore

Can not stick nav to the top.. middle done with flex,and nav won't get to the top