--allow-worker
稳定性: 1.1 - 处于活跃开发中
在使用 权限模型 时,默认情况下该进程无法创建任何工作线程。出于安全原因,除非用户在主 Node.js 进程中显式传递 --allow-worker 标志,否则调用会抛出 ERR_ACCESS_DENIED。
【When using the Permission Model, the process will not be able to create any
worker threads by default.
For security reasons, the call will throw an ERR_ACCESS_DENIED unless the
user explicitly pass the flag --allow-worker in the main Node.js process.】
示例:
【Example:】
const { Worker } = require('node:worker_threads');
// Attempt to bypass the permission
new Worker(__filename); $ node --permission --allow-fs-read=* index.js
Error: Access to this API has been restricted
at node:internal/main/run_main_module:17:47 {
code: 'ERR_ACCESS_DENIED',
permission: 'WorkerThreads'
}