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

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

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 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!