3

I have in package.json (NOT BASH, NOT SH, NOT ZSHELL, NOT FISH).

So after we established the fact that this is my package.json file, let me present it to you:

package.json

  "scripts": {
    "dev": "NODE_ENV=myValue myProgram"
  }

I want to add more vars (e.g. MYVAR=myOtherValue) to above file, which is my package.json file. How can I do that (adding more vars to my package.json file)?

Let me be clear that I do not want to read the manpage of bash or zshell, or fish, or sh. This is why I put the question in here and did not read the manpage - otherwise I would not put it here and would have read the manpage. Thank you for understanding.

RobC
  • 22,977
  • 20
  • 73
  • 80
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • 1
    Space separated eg `NODE_ENV=myValue MYVAR=myOtherValue myProgram` see https://stackoverflow.com/questions/26189662/how-set-multiple-env-variables-for-a-bash-command – generalhenry Apr 27 '18 at 14:03
  • 1
    Possible duplicate of [How set multiple env variables for a bash command](https://stackoverflow.com/questions/26189662/how-set-multiple-env-variables-for-a-bash-command) – k0pernikus Apr 27 '18 at 14:06
  • 1
    Its not a duplicate. I am asking about nodeJs and package.json. From a Developer Standpoint (lets say I use Windows) this has nothing to do with bash at all. (Believe me we have 99% of Windows Developers who never heard of bash in their entire life and dont need to and dont want to) – Stephan Kristyn Apr 27 '18 at 14:12
  • 1
    Please don't reduce answers to just contain a one-liner. The additional information was provided to present context. – k0pernikus Apr 27 '18 at 14:15
  • I did not ask about bash – Stephan Kristyn Apr 27 '18 at 14:16
  • Related: https://stackoverflow.com/questions/17978685/is-it-possible-to-set-multiple-environment-variables-in-one-cmd-line-statement/27901090 – k0pernikus Oct 27 '21 at 16:15

2 Answers2

9

Your script should be:

"dev": "NODE_ENV=myValue MYVAR=myOtherValue myProgram"

as you can add multiple environment variables when space-separated.

This stems from the common behavior from terminals like bash, where you can set multiple env variables on the fly:

FOO1=baz FOO2=fnord FOO3=baz env | grep FOO
FOO1=baz
FOO2=fnord
FOO3=baz
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
-1

I am with Stevek on this one, I read the answer (the duplicate answer) and am frustrated with the references to bash. I am on a windows system that uses Powershell. I want to pass multiple environmental variables and have it work in windows systems using Powershell. Any reference to *nix commands etc unless to enable cross-system use is mudding the waters.

So far this answer is not answered. So will add what I found

This questions tells you how to pass 1 variable. How to set environment variables from within package.json

 "start": "set NODE_ENV=YOURENV&&node start.js"

Now how to pass more than 1? That is still the question.

I was told that using cross-env is the best: cross-env NODE_ENV=production my-command

The answer was given here: https://github.com/kentcdodds/cross-env/issues/15

"scripts": {
  "debug": "cross-env NODE_PATH=. DEBUG=app:* nodemon bootload.js"
}

However, cross-env does not use PowerShell but depreciate cmd shell on windows. So back to the main issue. [unless you make this change https://github.com/kentcdodds/cross-env/issues/192#issuecomment-513341729]

ben
  • 1
  • 1