node.jsnpmenvironment-variablesnpm-scripts

Pass more than one variable to a package.json script


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.


Solution

  • 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