Node.js, Express, Socket.io App Connection Error
I've got a simple app which uses socket.io module for node.js. When i run my server with node express_server.js command it works ok, but when i want to open my http://localhost:808
Solution 1:
There is no router defined. Try add this after creating the app (var app = express()):
app.get('/', function(req, res) {
// res.send('hello world');
res.sendfile('index.html');
});
Solution 2:
Express is a framework that amongst other stuff replaces the 'http' module. You appear to be trying to use both together. Try this:
var express = require('express'),
var app = express();
app.get('/', function(req, res) {
res.sendfile('index.html');
});
var port = Number(process.env.PORT || 8080);
app.listen(port, function() {
console.log("Listening on " + port);
});
Credit to Ben for the nudge on the get method.
Post a Comment for "Node.js, Express, Socket.io App Connection Error"