Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
I'm using Windows 10 and I can't seem to use set the environment variable on nodejs on my terminal

I'm a beginner to nodejs. I created two json files with different names and mail.host. The first one is called development.json

{
    "name": "My Express App - Development",
    "mail": {
        "host": "dev-mail-server"
    }
}

and the other one is production.json

{
    "name": "My Express App - Production",
    "mail": {
        "host": "prod-mail-server"
    }
}

after using executing this code below on my index.js, the terminal prints the same output even after using set NODE_ENV="production" in the terminal. What seems to be the problem in my code? Thank you so much!

console.log(`Application Name: ${config.get('name')}`)
console.log(`Mail Server: ${config.get('mail.host')}`)
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I presume you're using the config package. I've created an example app in Windows 10 to test all this using the below file structure. I suspect you just need to omit the quotes, e.g.

SET NODE_ENV=development

when you're setting the NODE_ENV variable.

Here's the app details:

Folder Structure

project
|  app.js
|
└──config
    | development.json
    | production.json

app.js

const config = require('config');
console.log(`Application Name: ${config.get('name')}`);
console.log(`Mail Server: ${config.get('mail.host')}`);

development.json

{ "name": "My Express App - Development", "mail": { "host": "dev-mail-server" } }

production.json

{ "name": "My Express App - Production", "mail": { "host": "prod-mail-server" } }

Command Prompt Test

If I open a command window and enter:

SET NODE_ENV=development
node app.js

I get the output:

Application Name: My Express App - Development
Mail Server: dev-mail-server

If I type:

SET NODE_ENV=production
node app.js

I get the output:

Application Name: My Express App - Production
Mail Server: prod-mail-server

Powershell Test

If I open a Powershell window and enter:

$env:NODE_ENV="development"
node app.js

I get the output:

Application Name: My Express App - Development
Mail Server: dev-mail-server

If I enter:

$env:NODE_ENV="production"
node app.js

I get the output:

Application Name: My Express App - Production
Mail Server: prod-mail-server

Likewise

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda