在 ubuntu 14.04 VPS 上执行.js文件错误

Executing .js file on ubuntu 14.04 VPS error

本文关键字:执行 js 文件 错误 VPS ubuntu      更新时间:2023-09-26

当我尝试在 ubuntu 上运行我的 sell.js javascript 时,您好,我收到此错误:

节点卖出.js

socket timed out
socket closed
connecting to 72.165.61.175:27018
connected
encrypt request
/var/www/bot/node_modules/steam/lib/steam_client.js:150
  var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirna
                                         ^
TypeError: Object #<Object> has no method 'publicEncrypt'
    at SteamClient.handlers.(anonymous function) (/var/www/bot/node_modules/steam/lib/steam_client.js:150:42)
    at SteamClient._netMsgReceived (/var/www/bot/node_modules/steam/lib/steam_client.js:106:26)
    at Connection.emit (events.js:95:17)
    at Connection._readPacket (/var/www/bot/node_modules/steam/lib/connection.js:50:8)
    at Connection.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at Connection.Readable.push (_stream_readable.js:128:10)
    at TCP.onread (net.js:529:21)
/

var/www/bot/node_modules/steam/lib/steam_client.js 中的代码:

handlers[EMsg.ChannelEncryptRequest] = function(data) {
  this._connection.setTimeout(0);
  this.emit('debug', 'encrypt request');
  this._tempSessionKey = require('crypto').randomBytes(32);
  var cryptedSessKey = require('crypto').publicEncrypt(fs.readFileSync(__dirname + '/public.pub'), this._tempSessionKey);
  var keyCrc = require('buffer-crc32').signed(cryptedSessKey);
  var encResp = new schema.MsgChannelEncryptResponse().encode();
  var body = new ByteBuffer(encResp.limit + 128 + 4 + 4, ByteBuffer.LITTLE_ENDIAN);
  body.append(encResp);
  body.append(cryptedSessKey);
  body.writeInt32(keyCrc);
  body.writeUint32(0);
  this._send(EMsg.ChannelEncryptResponse, body.flip());
};

我做了 npm 安装 --保存加密,但它不起作用,我总是收到此错误.. 如果有人知道如何解决这个问题,请告诉我。

根据反馈和测试,问题在于目前 Ubuntu 14.04 仓库有 Node 0.10 分支。在此分支中,crypto.publicEncrypt API 函数不存在。您必须安装 4.x 或 5.x 版节点.js才能使用这些功能。

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

对于节点.js v4:

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

或者,对于 Node.js v5

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

可选:安装构建工具

要从 npm 编译和安装本机插件,您可能还需要安装构建工具:

sudo apt-get install -y build-essential