Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
Next js run different env variables

I am using NextJS. I need to create 3 type of environments:

  1. development
  2. staging
  3. production

I need to run on each env. specific variables.
For development i have .env, for productiuon i have .env.production and for staging i have .env.staging. My scrips looks like this:

"scripts": {
  "dev": "next dev -p 3001",
  "build": "next build",
  "start": "next start",
},

For simulating staging env. i created this:

"start:staging": "NODE_ENV=staging next dev -p 3001",

But when i check console.log(process.env.NODE_ENV, 'env variable'); i get development.
What i do wrong and how to get the proper variables?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are running next dev wich makes your application runs with developmento mode, thats why you get development.

Take a look at https://nextjs.org/docs/api-reference/cli#development

If you whant to use next.js build in env features you have the follow their docs https://nextjs.org/docs/basic-features/environment-variables#default-environment-variables.Basically you can have 3 environment files, local, development and production and they will be used when running the application with next dev and next start. The local env files always overrides the others, do not commit it to your project or your dev and production files wont be used.

If you want to do the exactly thing you said (development, staging and production) you will have to override next env by yourself. You can achieve this using dotenv.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda