Answer the question
In order to leave comments, you need to log in
Why does Node.js not run script on VDS?
Hello, there was a problem, I transferred the project to VDS and I'm trying to run the Node.js server script
, but for some reason the script does not load, the node and npm packages are standing here, the script code is the simplest, so to speak, and does not work
var io = require('socket.io').listen(8080);
io.sockets.on('connection', function (socket) {
var ID = (socket.id).toString().substr(0, 5);
var time = (new Date).toLocaleTimeString();
socket.json.send({'event': 'connected', 'name': ID, 'time': time});
socket.broadcast.json.send({'event': 'userJoined', 'name': ID, 'time': time});
socket.on('message', function (msg) {
var time = (new Date).toLocaleTimeString();
socket.json.send({'event': 'messageSent', 'name': ID, 'text': msg, 'time': time});
socket.broadcast.json.send({'event': 'messageReceived', 'name': ID, 'text': msg, 'time': time})
});
socket.on('disconnect', function() {
var time = (new Date).toLocaleTimeString();
io.sockets.json.send({'event': 'userSplit', 'name': ID, 'time': time});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question