启用


【Enabling】

--experimental-policy 标志可以在加载模块时启用策略的功能。

【The --experimental-policy flag can be used to enable features for policies when loading modules.】

一旦设置完成,所有模块必须遵守传递给标志的策略清单文件:

【Once this has been set, all modules must conform to a policy manifest file passed to the flag:】

node --experimental-policy=policy.json app.js 

策略清单将用于对 Node.js 加载的代码施加约束。

【The policy manifest will be used to enforce constraints on code loaded by Node.js.】

为了减少对磁盘上策略文件的篡改,可以通过 --policy-integrity 提供策略文件本身的完整性。这允许在文件被修改的情况下仍然运行 node 并验证策略文件的内容。

【To mitigate tampering with policy files on disk, an integrity for the policy file itself may be provided via --policy-integrity. This allows running node and asserting the policy file contents even if the file is changed on disk.】

node --experimental-policy=policy.json --policy-integrity="sha384-SggXRQHwCG8g+DktYYzxkXRIkTiEYWBHqev0xnpCxYlqMBufKZHAHQM3/boDaI/0" app.js