search

Home  >  Q&A  >  body text

javascript - Xiaobai's solution: How to set the NODE_NEV environment variable of nodejs express under mac

Problem requirement: The interface IP will change during project testing. I want to reduce the need to manually modify the IP address of the interface each time by setting NODE_NEV.

Problem description:
Configuration method of NODE_NEV in express

The following is the code found, but it does not take effect after startup.

common.js

var envJson = {
    "development": {
    "facebook_app_id": "facebook_dummy_dev_app_id",
        "facebook_app_secret": "facebook_dummy_dev_app_secret",
},
    "production": {
    "facebook_app_id": "facebook_dummy_prod_app_id",
        "facebook_app_secret": "facebook_dummy_prod_app_secret",
    }
}

exports.envJson = function() {
    var node_env = process.env.NODE_ENV || env.development;
    return envJson[node_env];
};

app.js

var envJson = common.envJson();
var facebook_app_id = envJson.facebook_app_id;
女神的闺蜜爱上我女神的闺蜜爱上我2766 days ago683

reply all(1)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-28 09:29:34

    Edit package.json’s scripts

    "scripts":{
        "start": "NODE_ENV=production node index.js",
        "dev": "NODE_ENV=development node index.js"
    }

    Start the production environment

    npm run start

    Start the development environment

    npm run dev

    reply
    0
  • Cancelreply