Staging environment displaying as 'production' in $_ENV when it should be 'staging'

======== TEMPLATE BUG FORM ========

Wappler Version : Latest v5
Operating System : Mac M1
Server Model: NodeJS
Database Type: Mysql
Hosting Type: Docker remote (DO)

Expected behavior

What do you think should happen?

I have set my target usage as ‘staging’ and so I should retrive ‘staging’ as the NODE_ENV parameter, instead I’m returning ‘production’.

Hi mgaussie, check whether the value for the ENV variable has been saved correctly under Server Connect Settings -> Environment for the Staging target.

If a new project target is created after the ENV variables have already been created with their values, then these values get copied over to the new project target.

Hi @guptast guptast, I don’t have anything in SC Settings > Environment, I assumed as for the development target it automatically outputs ‘development’ and then for remote server it outputs ‘production’ it would automatically set the NODE_ENV to the environment usage selected in the target?

Even though I do have an output without manually setting the environment, do I need to do this manually?

Sorry, I didn’t understand the setup with NODE_ENV. Is it an ENV variable, setup under Globals -> Input -> $_ENV?

The environment variables are defined under Globals -> Input -> $_ENV. The values for these variables are defined under SC Settings -> Environment for each project target.

Ok, maybe i’m just assuming Wappler is setting the config.

When I output $_ENV in my development environment I get the following by default:

1. DEBUG: "server-connect:*"
2. HOME: "/root"
3. HOSTNAME: "..."
4. NODE_ENV: "development"
5. NODE_VERSION: "16.20.0"
6. PATH: "/opt/node_app/node...l"
7. PORT: "3000"
8. PUPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome"
9. PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: "true"
10. PWD: "/opt/node_app"
11. REDIS_HOST: "redis"
12. TERM: "xterm"
13. YARN_VERSION: "1.22.19"

So you can see here the NODE_ENV is outputting automatically as ‘development’. Is it fair to assume that when a target is set to staging, or production that Wappler should also automatically handle this by replacing development with the usage setting from the Project Settings?

It seems more like an output of the Dockerfile. I don’t know how the environment variables defined in this file are accessible within your APIs, if these are available via the API component.

In my setup, I define the ENV variables manually under Globals along with their values for each project target under the SC Settings. This way, the ENV variables are accessible in the APIs and their values can be different, if required, for different tagrets.

1 Like

Thank you! Unless the team provide some insight into automatic settings I’ll proceed the same way as you. Thank you for your responses!

1 Like

No problems at all. Glad to be of some help :slight_smile:

1 Like

You can define and use environment variables as explained in:

1 Like

@George NODE_ENV is a special variable, please re-read post 5 and clarify the user :wink:

Edit: probably a question for @patrick

1 Like

I think this is a bug.

$_ENV.NODE_ENV

Returns development on development.
But it returns production on staging.

That can’t be right and has (as far as I can see) nothing to do with manual env settings.

1 Like

This is still an issue for me… Would be great if this could be picked up.

Is this fixed?

umm, yeup. Version 6.7.3