How to set NODE_ENV to production/development in O

2020-01-24 10:18发布

For use in express.js environments. Any suggestions?

13条回答
家丑人穷心不美
2楼-- · 2020-01-24 10:44
heroku config:set NODE_ENV="production"
查看更多
三岁会撩人
3楼-- · 2020-01-24 10:44

If you are on windows. Open your cmd at right folder then first

set node_env={your env name here}

hit enter then you can start your node with

node app.js

it will start with your env setting

查看更多
啃猪蹄的小仙女
4楼-- · 2020-01-24 10:46

in package.json:

{
  ...
  "scripts": {
    "start": "NODE_ENV=production node ./app"
  }
  ...
}

then run in terminal:

npm start
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2020-01-24 10:48

export NODE_ENV=production is bad solution, it disappears after restart.

if you want not to worry about that variable anymore - add it to this file:

/etc/environment

don't use export syntax, just write (in new line if some content is already there):

NODE_ENV=production

it works after restart. You will not have to re-enter export NODE_ENV=production command anymore anywhere and just use node with anything you'd like - forever, pm2...

For heroku:

heroku config:set NODE_ENV="production"

which is actually default.

查看更多
smile是对你的礼貌
6楼-- · 2020-01-24 10:48

Windows CMD -> set NODE_ENV=production

Windows Powershell -> $env:NODE_ENV="production"

MAC -> export NODE_ENV=production

查看更多
我命由我不由天
7楼-- · 2020-01-24 10:51

On OSX I'd recommend adding export NODE_ENV=development to your ~/.bash_profile and/or ~/.bashrc and/or ~/.profile.

Personally I add that entry to my ~/.bashrc and then have the ~/.bash_profile ~/.profile import the contents of that file, so it's consistent across environments.

After making these additions, be sure to restart your terminal to pick up settings.

查看更多
登录 后发表回答