检测是否支持 crypto


可以在不包括支持 crypto 模块的情况下构建 Node.js, 这时, 调用 require('crypto') 将 导致抛出异常.

let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('不支持 crypto!');
}

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!');
}