node.js express socket.io port 3000 in use

2020-05-20 08:47发布

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.

8条回答
Root(大扎)
2楼-- · 2020-05-20 09:25

for me helps to make use 3000 || 3333, and it's fix the issue

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-05-20 09:27

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

查看更多
登录 后发表回答