gpt4 book ai didi

javascript - Nodejs get throw er;//未处理的 'error'事件

转载 作者:行者123 更新时间:2023-11-30 16:00:50 25 4
gpt4 key购买 nike

<分区>

这是我在 NodeJs 上的第一个程序,我尝试在上面使用 ExpressSocket.io。按照下面的代码创建简单的项目后,我得到

throw er; // Unhandled 'error' event

错误,我在谷歌上搜索了更多教程,但我找不到我的代码问题是什么

安装包:

{
"name": "signalAndroidServerApplication",
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "~1.12.4",
"cookie-parser": "~1.3.5",
"express": "~4.12.4",
"socket.io": "latest"
}
}

我的 Node :

var socket = require('socket.io');
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = socket.listen(server);
var port = process.env.PORT || 3000;

server.listen(port, function () {
console.log('Server listening at port %d', port);
});

io.on('connection', function (socket) {
socket.on('new_count_message', function (data) {
console.log('new_count_message' + data);
io.sockets.emit('new_count_message', {
new_count_message: data.new_count_message
});
});
});

完整错误:

events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Object.<anonymous> (/var/www/signal/nodeJs/server.js:8:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com