Node.js NODEJS+;WS-LIBRARY=缓冲区分配错误

Node.js NODEJS+;WS-LIBRARY=缓冲区分配错误,node.js,express,websocket,buffer,Node.js,Express,Websocket,Buffer,我们正在构建一个简单的express+websocket库(ws)。 当我们运行这样一个简单的示例时: var express = require('express'); var http = require('http'); var WebSocket = require('ws'); const app = express(); //initialize a simple http server const server = http.createServer(app); //init

我们正在构建一个简单的express+websocket库(ws)。 当我们运行这样一个简单的示例时:

var express = require('express');
var http = require('http');
var WebSocket = require('ws');

const app = express();

//initialize a simple http server
const server = http.createServer(app);

//initialize the WebSocket server instance
const wss = new WebSocket.Server( server );

wss.on('connection', function connection(ws) {

    //connection is up, let's add a simple simple event
    ws.on('message', function incoming(message) {

        //log the received message and send it back to the client
        console.log('received: %s', message);
        ws.send('Hello, you sent -> '+ message);
    });

    //send immediatly a feedback to the incoming connection    
    ws.send('Hi there, I am a WebSocket server');
});

//start our server
server.listen(process.env.PORT || 8999, () => {
    console.log('Server started on port'+ server.address().port + ' 
:)');
});
但是,当我们运行应用程序时,出现了以下错误:

ws constants.js:8 EMPTY_BUFFER: Buffer.alloc(0), ^ TypeError: 
Buffer.alloc is not a function
你知道这是关于什么的吗?谷歌指出,由于版本冲突,在一些情况下。 如果我键入:nodejs-v,它将显示:v4.2.6


谢谢你的帮助。

我已经找到问题了。。。这是一个软件包版本问题

我卸载了所有内容,并使用以下行重新安装了关于nodejs的所有内容:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
我升级到nodejs 8.x。在那之后,我重新开始了我的治疗,一切正常。 后来我发现了一些关于使用WS-library的正确版本的评论

问候