--allow-net
稳定性: 1.1 - 积极开发
¥Stability: 1.1 - Active development
使用 权限模型 时,进程默认将无法访问网络。尝试这样做将抛出 ERR_ACCESS_DENIED
,除非用户在启动 Node.js 时明确传递 --allow-net
标志。
¥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',
}