Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!