javascript - Xiaobai's solution: How to set the NODE_NEV environment variable of nodejs express under mac
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-28 09:27:34
0
1
666

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;
女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(1)
过去多啦不再A梦

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template