确定加密支持是否不可用


可以在不支持 crypto 模块的情况下构建 Node.js。 在这种情况下,调用 require('crypto') 将导致抛出错误。

let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('crypto support is disabled!');
}

It is possible for Node.js to be built without including support for the crypto module. In such cases, calling require('crypto') will result in an error being thrown.

let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('crypto support is disabled!');
}