Hello I am having trouble starting up my server.js. Every time that I would run node towards it. It wills always show this error "listening on *:3000". Here is my code for my server.js.
var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
app.get('/chat', (req, res) => {
res.sendFile(__dirname '/chat.html');
});
io.on('connection', (socket) => {
console.log('User Online');
socket.on('codeboard-message', (msg) => {
console.log('message: ' msg);
socket.broadcast.emit('message-from-others', msg);
});
});
var server_port = process.env.YOUR_PORT || process.env.PORT || 3000;
http.listen(server_port, () => {
console.log('listening on *:' server_port);
});
Do I have to use a different port or am I missing a line of code for this server to work? Any help will be appreciated!
CodePudding user response:
var app = require('express')();
var http = require('http').createServer(app);
var server_port = process.env.PORT || 3000;
http.listen(server_port, () => {
console.log('listening on *:' server_port);
});
try only this without socket io. If it works, add socket io code