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

87
Views
How to export correct object from Node.js on Windows 10 machine using NPM?

As far as I know and as far as it's relevant, there is 2 ways to run project on Windows 10 machine, while passing variables:

  1. NODE_ENV=production && npm run dev
  2. npm run prod

What's going on here?.. Why first example runs smoothly, while the second - returns undefined?..

What I get with second example is currentEnv = "production", but exportableEnvName = undefined.

Any ideas how to solve it? And why it happens? Thanks!

P.S. I would prefer in not using other packages as a solution.

Code example:

config.js

const environments = {};

environments.dev = {
    httpPort: 3000,
    httpsPort: 3001,
}

environments.production = {
    httpPort: 5000,
    httpsPort: 5001,
}

const currentEnv = typeof process.env.NODE_ENV === 'string' ? process.env.NODE_ENV.toLowerCase() : '';
const exportableEnvName = typeof environments[currentEnv] === 'object' ? currentEnv : 'dev';

module.exports = environments[exportableEnvName];

package.json

{
  "scripts": {
    "dev": "node .",
    "prod": "SET NODE_ENV=production && node ."
  },
}
about 4 years ago · Juan Pablo Isaza
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!