我正在尝试启动本地服务器,但出现大量错误,有人可以告诉我正在发生什么以及如何解决此问题吗?
这是我尝试node bot.js
C:\Users\Admin\Desktop\Client\src\Local Server>node bot.js
C:\Users\Admin\Desktop\Client\src\Local Server\bot.js:7
net.createServer(socket = > {
^
SyntaxError: Unexpected token >
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
bot.js的来源
net = require('net');
var clients = [];
const char = String.fromCharCode(0);
net.createServer(socket = > {
socket.setNoDelay(true);
clients.push(socket);
console.log("Connected.");
socket.on('data', data = > {
var x = data.readFloatBE(0);
var y = data.readFloatBE(4);
update(socket, x, y);
})
;
socket.on('error', error = > {}
)
;
socket.on('close', () = > {
clients.splice(clients.indexOf(socket), 1);
console.log("Closed.");
})
;
socket.on('end', () = > {
// ...
}
)
;
function update(sender, x, y) {
for (var i = 0; i < clients.length; i++) {
if (clients[i] !== sender) {
clients[i].write(x + ":" + y + char);
}
}
}
}).
listen(8888, '127.0.0.1');
console.log("Listening at: 8888")
package-lock.json的来源
{
"lockfileVersion": 1
}
答案 0 :(得分:2)
仅箭头功能没有空格,将= >
替换为=>