Can you tell me how to use express’s app.set? Use app.set in app.js and restore default in other js inside.

  node.js, question

For example, inapp.jsinside

var express = require('express');
 var app = express();
 app.set('env', 'production');
 console.log(app.get('env'));  //production
 var routes = require('./routes/index');
 app.use('/', routes);


var express = require('express');
 console.log(express().get('env'));  //development

In other words, after setting the environment, how to read the environment? Because I can see, in./routes/index.jsFor insideexpress()This is tantamount to creating a new one.expressExample, so the setting is reset is normal, but I don’t know how to read the set’ env’

I am Xiao Bai, express will only be required once, that is to say, if you are required in app.js inside, then your app.set is in inside, the instance of your app. If needed in other files, you should be App = Required (the path where App. JS is located), and then use app.get () …