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

89
Vistas
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
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