Does NODE_ENV affect build environment or only for runtime environment

System Information
  • Strapi Version: 3.6.2

Hi everyone,

I have a very simple question. Does the NODE_ENV affect in any way the strapi build command or is it strictly a runtime setting?

Thank you

Both, specifically in the build it takes into account the optional url and admin.url keys from the server.js and depending on if you have any ./config/env/${NODE_ENV}/server.js files.

Hmmm does that mean if I am running the build in a container I would need to build the container per environment?

I was thinking of building the container once and then at runtime (during docker run) I would set the correct NODE_ENV to dev, staging for example

Effectively yes because the build is static and it’s react CSR meaning the “address” to the Strapi backend needs to be compiled into the static generated files, after the admin is built then the Strapi backend is just acting as basically a webserver that is serving those static files.

The client side loads the files and makes requests using the compiled URL and it needs to know the backend address to do that.

I don’t understand. Even if Strapi is a CSR you would probably be using relative URLs and the full URL is decided at runtime depending on the server serving those static files, in this case it is Strapi.

I can also imagine that the files in /config/env/${NODE_ENV}/server.js can also be selected on server start at runtime depending on $NODE_ENV.

The only thing that comes to my mind is whether you want to produce different containers that contain minified and/or obfuscated admin panel vs. non-minified with debug symbols for dev environments.

What am I missing?

I guess what you mentioned is related to Deployment but in my case the admin panel and the frontend are on the same server.

It is always listening on 0.0.0.0