Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Having Trouble Running my Server.JS. Listening Error

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!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!