How does GAE (Google App Engine) treat NODE_ENV
on deployment and run with a NodeJS runtime?
Google docs clearly states that some variables are automatically set and cannot overridden except the `NODE_ENV. How do you do that?
I have tried setting it in app.yaml
and even though it is shown as properly set in the GAE console it is not reflected in the app.
I have tried using non-standard value in the app.yaml
such as NODE_ENV: foobar
and the build process does recognize it but the value that the application reads is always production
.
warn - You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
1 Answer 1
Since GAE automatically sets it to "production" in production environments, my take to handle NODE_ENV
in Google App Engine (GAE) is to not directly modify NODE_ENV
.
You should use custom environment variables to manage your specific configuration needs.
- Set a custom environment variable in your
app.yaml
:
env_variables:
CUSTOM_NODE_ENV: "foobar"
- Access the custom variable in your application:
const customEnv = process.env.CUSTOM_NODE_ENV || 'default_value';
console.log(customEnv); // where "foobar" should log