--allow-net


稳定性: 1.1 - 处于活跃开发中

使用 权限模型 时,默认情况下该进程将无法访问网络。除非用户在启动 Node.js 时显式传递 --allow-net 标志,否则尝试访问网络将抛出 ERR_ACCESS_DENIED 错误。

【When using the Permission Model, the process will not be able to access network by default. Attempts to do so will throw an ERR_ACCESS_DENIED unless the user explicitly passes the --allow-net flag when starting Node.js.】

示例:

【Example:】

const http = require('node:http');
// Attempt to bypass the permission
const req = http.get('http://example.com', () => {});

req.on('error', (err) => {
  console.log('err', err);
}); 
$ node --permission index.js
Error: connect ERR_ACCESS_DENIED Access to this API has been restricted. Use --allow-net to manage permissions.
  code: 'ERR_ACCESS_DENIED',
}