An app built using express.js (3.x) used to have the following in its app.js
app.set('port', process.env.PORT || 3000);
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
Now, with the latest build express.js (4.2), the above code is missing. Instead, there seem to be some error handlers for production and development.
I am a beginner. Kindly help me understand what does this mean ? Express doesn't need a port to start off with ? And if there is no http.createServer(app)
, how does it even work now ?
If the stated code is not present, then express has probably generated something like this for you:
var app = module.exports = express.createServer();
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
It does have a http.createServer()
in the beginning. The first argument to app.listen()
is the port number. You can change it there. The callback is executed once the server receives a request on that port.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.