node.js - Ubuntu 12.04 中的 Socket.io 错误

标签 node.js mongodb socket.io ubuntu-12.04

我刚刚将 node.js、npm 和 mongodb 安装到了全新的 Ubuntu 12.04 服务器上。当我尝试打开我的网站时,出现此错误:

/home/proj/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:402
        return doneCallback(null, Buffer.concat([sizeBuffer, stringToBuffer(pa
                                         ^
TypeError: Object function Buffer(subject, encoding, offset) {
  if (!(this instanceof Buffer)) {
    return new Buffer(subject, encoding, offset);
  }

  var type;

  // Are we slicing?
  if (typeof offset === 'number') {
    this.length = coerce(encoding);
    this.parent = subject;
    this.offset = offset;
  } else {
    // Find the length
    switch (type = typeof subject) {
      case 'number':
        this.length = coerce(subject);
        break;

      case 'string':
        this.length = Buffer.byteLength(subject, encoding);
        break;

      case 'object': // Assume object is an array
        this.length = coerce(subject.length);
        break;

      default:
        throw new Error('First argument needs to be a number, ' +
                        'array or string.');
    }

    if (this.length > Buffer.poolSize) {
      // Big buffer, just alloc one.
      this.parent = new SlowBuffer(this.length);
      this.offset = 0;

    } else {
      // Small buffer.
      if (!pool || pool.length - pool.used < this.length) allocPool();
      this.parent = pool;
      this.offset = pool.used;
      pool.used += this.length;
    }

    // Treat array-ish objects as a byte array.
    if (isArrayIsh(subject)) {
      for (var i = 0; i < this.length; i++) {
        this.parent[i + this.offset] = subject[i];
      }
    } else if (type == 'string') {
      // We are a string
      this.length = this.write(subject, 0, encoding);
    }
  }

  SlowBuffer.makeFastBuffer(this.parent, this, this.offset, this.length);
} has no method 'concat'
    at /home/proj/node_modules/socket.io/node_modules/engine.io/node_modules/engine.io-parser/lib/index.js:402:42

这可能是什么原因造成的?本地主机中一切正常。

最佳答案

Buffer.concat 仅在 Node 0.8 中受支持。您需要将 Node 升级到最新版本。 Ubuntu 12.04仅提供Node 0.6

要升级,您可以运行以下命令

$ npm install -g n
$ n stable

这会将最新的 Node 安装到/usr/local/bin。

您可以使用以下方式运行您的 Node 应用程序

$ /usr/local/bin/node path-to-your-node-app

了解有关 Node 二进制管理的更多信息,请访问 https://github.com/tj/n ,它可以帮助您管理多 Node 二进制安装。

关于node.js - Ubuntu 12.04 中的 Socket.io 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26894704/

相关文章:

node.js - 定时器删除记录+一个条件

node.js - Redis 上的 socket.io-emitter 每次发送数据都要初始化

node.js - 在 Microsoft Bot 构建器 node.js 中处理由 Slack 中的提示生成的先前按钮的输入时出现问题

node.js - 删除与 RavenDB 中的条件匹配的特定集合的多个文档

javascript - 如何使用 Puppeteer 设置、更改或阻止时区(系统时间)?

mongodb - 如何删除不存在的docker镜像

node.js - 从单个 Node.js 应用程序打开多个 Mongo 连接是个好主意吗?

node.js - 这是内存泄漏吗?

ssl - JSSEHelper 不提供正确的 SSLSocketFactory 用于在 Websphere 8.0 中建立安全连接

javascript - 最小化 JavaScript 中客户端/服务器之间发送的数据