DEV Community

Discussion on: Pass arguments from the command line to a Node script

Collapse
shane325 profile image
Shane Barry

Alternatively you can do

node app.js NODE_ENV=production

and fetch that in your code

let env = process.env.NODE_ENV

make use of scripts in your package.json file to make this even easier

"scripts": {
    "dev": "node app.js NODE_ENV=development",
    "prod": "node app.js NODE_ENV=production"
  }

now you can run

npm run dev

or

npm run prod

depending on what variable you want

Collapse
kepta profile image
Kushan Joshi

While NODE_ENV works just fine for this case, they arenโ€™t an idiomatic solution for thr passing of information from cli command to program.