0

I want to set/change user variable in my windows/Linux system. one of them is my APP_SOME_VAR variable.

When I run env in the command line I'm getting a list of my user variables.

When I run this code in my file.js it doesn't change my variable in the command line.

const { execSync } = require('child_process');

let output = execSync(`echo blabla && set APP_SOME_VAR=blabla`);

After I run the file, I do this in the command line:

node app.js
env | grep SOME

But I get nothing from: APP_SOME_VAR

How to do that with nodejs?

Jon Sud
  • 10,211
  • 17
  • 76
  • 174
  • 1
    Does this answer your question? [How to set environment variables in a cross-platform way?](https://stackoverflow.com/questions/32446734/how-to-set-environment-variables-in-a-cross-platform-way) – Benson Nov 03 '19 at 09:33
  • no, because I don't want to change the variable from package.json, only from my `file.js` file – Jon Sud Nov 03 '19 at 09:35
  • Usually, you can set environmental vars only temporarily, but https://stackoverflow.com/questions/42519452/is-it-possible-to-permanently-set-environment-variables has a workaround. – Benson Nov 03 '19 at 09:43

0 Answers0