Supporting multiple .env files

System Information
  • Strapi Version: v5

I have read the docs regarding env files,
but I feel like I am missing a crucial piece of information.
I do not want to have hardcoded values in these files, since these are uploaded to github. So i need an env() call.
But strapi says nowhere how to setup multiple .env files for this case. RIght now, my /config/env/development/plugins.ts looks like this

export default ({ env }) => {
  console.log("ACCESS_TOKEN_ID:", env("ACCESS_TOKEN_ID"));
  console.log("WEBHOOK_SIGNING_SECRET: ", env("WEBHOOK_SIGNING_SECRET"));
  console.log("NODE ENV: ", env("NODE_ENV"));
  // ...
  return {
    "mux-video-uploader": {
      enabled: true,
      config: {
        accessTokenId: env("ACCESS_TOKEN_ID"),
        secretKey: env("ACCESS_TOKEN_SECRET"),
        webhookSigningSecret: env("WEBHOOK_SIGNING_SECRET"),
        playbackSigningId: env("SIGNING_KEY_ID"),
        playbackSigningSecret: env("SIGNING_KEY_PRIVATE_KEY"),
      },
    },
    // ...
  };
};

I can see that i am under “development” node-env, but it still loads my values from .env and not from .env.development I don’t understand the whole concept of having multiple config/… setups if you can’t use multiple .env files.
Does this mean I have to setup the ENV PATH in my starting strapi comment? Is Strapi not supporting this out of the box?

Add .env files to gitignore and don’t push them to github?

What?
I have multiple .env files, the issue is that I can’t get Strapi to read from a different file depending on the environment, it always reads from .env
I want it to read .env.development when its in dev, and .env.stage when it’s in stage.
With the solution from the docs it seems that Strapi only supports one .env file,
and within that I’d have something like DEV_ACCESS_TOKEN, PROD_ACCESS_TOKEN, STAGE_ACCESS_TOKEN etc.
But I think that be weird so I feel like I am missing something.

Sorry, I misread your question.

You are asking about specifically having a production .env and a development .env on the same host? Instead of having a .env with development values on your local machine and one for deployment?

You can have two different files, and set the path to the file whenever you start strapi:

ENV_PATH=/absolute/path/to/.env npm run start
or
ENV_PATH=./.env.production npm run start

Or just manually rename-juggle two files locally? .env.production and .env.development — rename whichever one you need to .env when you need it?