javascript - In node.js do I need http when building a socket.io/express app? -


i have started using node.js , can build simple app responds requests , has basic routing using express framework.

i looking create using socket.io confused on use of 'http' module. understand http don't seem need following work:

var express = require('express'); var app = express();  app.get('/', function (req, res) {   res.sendfile(__dirname + '/index.htm'); });  app.listen(3000, function () {   console.log('example app listening on port 3000!'); }); 

i can serve html page on http without requiring http module explicitly such as:

var http = require('http'); 

if using express have use http module?

var express = require('express'); var app     = express(); var server  = require('http').createserver(app); var io      = require('socket.io').listen(server); ... server.listen(1234); 

however, app.listen() returns http server instance, bit of rewriting can achieve similar without creating http server yourself:

var express   = require('express'); var app       = express(); var socketio  = require('socket.io');  // app.use/routes/etc...  var server    = app.listen(3033); var io        = require('socket.io').listen(server);  io.sockets.on('connection', function (socket) {   ... }); 

source

http://stackoverflow.com/questions/17696801/express-js-app-listen-vs-server-listen 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -