How to set Environment variables from within packa

2019-01-04 05:25发布

How to set some Environment variables from within package.json to be used with npm start like commands

Here's what I currently have in my package.json:

{
  ...
  "scripts": {
    "help": "tagove help",
    "start": "tagove start"
  }
  ...
}

Here I want to set environment variables (like NODE_ENV) in the start script while still being able to start the app with just one command, npm start.

8条回答
你好瞎i
2楼-- · 2019-01-04 06:15

suddenly i found that actionhero is using following code, that solved my problem by just passing --NODE_ENV=production in start script command option.

if(argv['NODE_ENV'] != null){
    api.env = argv['NODE_ENV'];
  } else if(process.env.NODE_ENV != null){
    api.env = process.env.NODE_ENV;
  }

i would really appreciate to accept answer of someone else who know more better way to set environment variables in package.json or init script or something like, where app bootstrapped by someone else.

查看更多
走好不送
3楼-- · 2019-01-04 06:22
{
  ...
  "scripts": {
    "start": "ENV NODE_ENV=production someapp --options"
  }
  ...
}
查看更多
登录 后发表回答