遇到麻烦 运行 我的 Server.JS。听力错误
Having Trouble Running my Server.JS. Listening Error
您好,我在启动 server.js 时遇到问题。每次我都会 运行 指向它。它会始终显示此错误“listening on *:3000”。这是我的 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);
});
我是否必须使用不同的端口,或者我是否缺少一行代码才能使该服务器正常工作?任何帮助将不胜感激!
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);
});
在没有 socket io 的情况下只尝试这个。如果有效,请添加套接字 io 代码
您好,我在启动 server.js 时遇到问题。每次我都会 运行 指向它。它会始终显示此错误“listening on *:3000”。这是我的 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);
});
我是否必须使用不同的端口,或者我是否缺少一行代码才能使该服务器正常工作?任何帮助将不胜感激!
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);
});
在没有 socket io 的情况下只尝试这个。如果有效,请添加套接字 io 代码