Node.js: How to setup different variables for prod and staging

后端 未结 5 1093
说谎
说谎 2021-02-04 12:05

I\'m using Express and I need to use different credentials for each server (staging and production).

I could setup the variables in the server.coffee file but then I\'d

5条回答
  •  轮回少年
    2021-02-04 12:44

    If you don't want the logic for determining which config to use in each file (which would look pretty ugly), you'll have to export it somewhere.

    What I would suggest: Have a config.json file containing the different configs. The main file requires it and does something like config.default = config.(condition ? 'production':'development'). In all other files, you can now just do require('./config').default.

提交回复
热议问题