Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js express socket.io port 3000 in use

I've been following this(http://socket.io/get-started/chat/) tutorial on how to make a simple chat application using socket.io.

I tried to however use Express to create it and I was wondering why port 3000 is already in use? The code below will not work unless I change the port number.

/* Make the http server listen on port 3000. */
http.listen(3000, function(){
 console.log('listening on *:3000');
});

Does express use the port to do other things like routing or something? Is there a simple way to find what is happening on that port?

I may also be doing something dodgy with my require things:

var express = require('express');
var app = require('express')();
var http = require('http').Server(app);
var router = express.Router();
var io = require('socket.io')(http);

Thanks.

like image 914
himahimahima Avatar asked Jan 28 '15 04:01

himahimahima


People also ask

How do I stop 3000 port?

You can stop process with ctrl+C in the terminal window.

Why does Express use port 3000?

3000 is a somewhat arbitrary port number chosen because it allows you to experiment with express without root access (elevated privilege). Ports 80 and 443 are the default HTTP and HTTPS ports but they require elevated privilege in most environments.

How do I run localhost on port 3000?

0.0 or 127.0. 0 and it chose the port 3000 you can configure it to other ports too. So, when you type http://localhost:3000 in the addressbar of the browser you can see the first page hosted from your app. You can make use of etc/hosts file to a local name just like http://localhost:3000 to http://localapp.me too.


1 Answers

I ran into this problem too and I solved it by this:

Do not use npm start to start your web app

Use node app.js instead

like image 144
Ethan Yanjia Li Avatar answered Sep 24 '22 01:09

Ethan Yanjia Li