How to define and use environment variable on GCP?

I am having the following /config/server.js file:

module.exports = ({ env }) => ({
  //...
  url: env('WEBSITE', 'http://localhost:1337'),
});

I set the url property since I need it for some use case.
I deploy my strapi instance on GCP app engine, the app.yaml looks like so:

runtime: nodejs12
instance_class: F2
env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  // ...
  WEBSITE: 'https://my-website.com'

The environment variable WEBSITE is not taken into account on my GCP instance though , since url still equals http://localhost:1337 (which is the default from server.js) and I don’t understand why.

System Information
  • Strapi Version: 3.3.3
  • Operating System: Windows 10
  • Database: mysql
  • Node Version: 14
  • NPM Version: 6
  • Yarn Version:

Can you check the output of process.env.WEBSITE?

Actually, my understanding on how environment variables are propagated to children processes was inaccurate. As was the purpose of the url property in the server.js config.

I finally ended up with the following solution:

  • let server.url finally untouched (defaulting to ‘’)
  • use the process.env.WEBSITE variable directly where I need it
  • modify the start script in my package.json with this: ENV_PATH=${ENV_PATH:=./.env} strapi start
  • set ENV_PATH targeting a production environment file (.env.prod) in the app.yaml
  • set the WEBSITE variable in both .env and .env.prod files with appropriate values.

Not sure if that’s the optimal way of doing things, but this is solving the issue and allows me to keep my dev script in package.json unchanged (since it will use .env. by default).

1 Like

Hey @Eturcim, do you have a code example of how you set ENV_PATH targeting a production environment in your app.yaml file?

Hi @d_w

This was a year ago and I moved my instance to Heroku, so I don’t know if that’s still up-to-date. You can see that the node runtime is v12 for instance. Anyway, this is what my app.yaml looked like. I hope that can help:

runtime: nodejs12

instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  ENV_PATH: './.env.prod'
  DATABASE_NAME: 'strapi'
  DATABASE_USERNAME: 'your_db_username_here'
  DATABASE_PASSWORD: 'your_db_password_here'
  INSTANCE_CONNECTION_NAME: 'your_instance_name'
  DB_SOCKET_PATH: '/cloudsql/your_instance_name'

beta_settings:
  cloud_sql_instances: 'cloud_sql_instance_name'