Node.js process.allowedNodeEnvironmentFlags 属性
process.allowedNodeEnvironmentFlags是 process 模块内的 Process 类的内置应用程序编程接口,用于读取 NODE_OPTIONS 环境变量中允许的一组标志。
句法:
const process.allowedNodeEnvironmentFlags
参数:此 api 不接受任何参数作为参数。
返回值:此 api 返回 NODE_OPTIONS 环境变量中允许的一组标志。
示例 1:
index.js
// Node.js program to demonstrate the
// Process.allowedNodeEnvironmentFlags Property
// Importing process module
const process = require('process');
// Getting NodeEnvironmentFlags
const flags = process.allowedNodeEnvironmentFlags;
// Display the total size
console.log(flags.size)
index.js
// Node.js program to demonstrate the
// Process.allowedNodeEnvironmentFlags Property
// Importing process module
const process = require('process');
// Getting NodeEnvironmentFlags
process.allowedNodeEnvironmentFlags.forEach((flag) => {
// Display the lenght for each
console.log("Flag: ", flag, ", Length: ", flag.length)
});
使用以下命令运行index.js文件:
node index.js
输出:
104
示例 2:
index.js
// Node.js program to demonstrate the
// Process.allowedNodeEnvironmentFlags Property
// Importing process module
const process = require('process');
// Getting NodeEnvironmentFlags
process.allowedNodeEnvironmentFlags.forEach((flag) => {
// Display the lenght for each
console.log("Flag: ", flag, ", Length: ", flag.length)
});
使用以下命令运行index.js文件:
node index.js
输出:
Flag: --icu-data-dir , Length: 14
Flag: --title , Length: 7
..
..
..
..
Flag: --loader , Length: 8
Flag: -r , Length: 2
参考:
https://nodejs.org/dist/latest-v16.x/docs/api/process.html#process_process_allowednodeenvironmentflags