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

147
Vistas
Is it possible to set system environment variables from a node script?

I have an npm script like this that executes two node files:

package.json

{
  "scripts": {
    "my-target": "node setup.js && node run.js"
  }
}

Ideally, I can set environment variables in setup.js that can then be accessed in run.js.

setup.js

process.env.HELLO_WORLD=1

run.js

// Ideally prints `1`, instead prints undefined.
console.log(process.env.HELLO_WORLD);

Is something like this possible? Ideally the result of setting the environment variables in setup.js would be persistent, so that if I run

$ echo $HELLO_WORLD

from bash, that reference would still be there.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can set env vars when you run the main program:

HELLO_WORLD=hello npm run my-target

package.json:

  "scripts": {
    "my-target": "node setup.js && node run.js"
  },

setup.js:

console.info('setup', process.env.HELLO_WORLD);

run.js:

console.info('run', process.env.HELLO_WORLD);

Output will be

setup hello
run hello
about 4 years ago · Juan Pablo Isaza 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