Verify if my node.js instance is dev or production

前端 未结 3 542
别那么骄傲
别那么骄傲 2020-12-23 09:27

Right now, whenever I want to deploy a node.js server to my production server, I need to change all the IP/DNS/username/password for my various connection to my databases an

3条回答
  •  温柔的废话
    2020-12-23 09:57

    Normally you should run a node app in production like this:

    NODE_ENV=production node app.js

    Applications with Express, Socket.IO and other use process.env.NODE_ENV to figure out the environment.

    In development you can omit that and just run the app normally with node app.js.

    You can detect the environment in your code like this:

    var env = process.env.NODE_ENV || 'development';
    loadConfigFile(env + '.json', doStuff);
    

    Resources:

    How do you detect the environment in an express.js app?

提交回复
热议问题