You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the index.js the app object is being passed into http.Server(), which is later on called with http.listen(). Is there any difference or upside to this method over just using express' builtin app.listen();? Why and how does this work?
The text was updated successfully, but these errors were encountered:
You must pass an HTTP server instance to socket which is created by the line:
varhttp=require('http').Server(app);
Express' built in listen() function does return an HTTP server instance, so it is possible to use app.listen().
This:
varapp=require('express')();varhttp=require('http').Server(app);// The server instance is created here.vario=require('socket.io')(http);// The server instance is passed here.
Is equivalent to:
varapp=require('express')();varserver=app.listen(3033);// The server instance is returned from app.listen()vario=require('socket.io').listen(server);// The server instance is passed here.
However, I'm unsure if either provide any benefits over the other.
In the
index.js
theapp
object is being passed intohttp.Server()
, which is later on called withhttp.listen()
. Is there any difference or upside to this method over just using express' builtinapp.listen();
? Why and how does this work?The text was updated successfully, but these errors were encountered: