process.versions屬性是流程模塊的內置應用程序編程接口,用於獲取node.js模塊的版本及其依賴項。
用法:
process.versions
返回值:此屬性返回一個對象,其中包含node.js模塊的版本及其依賴項。
以下示例說明了Node.js中process.versions屬性的用法:
範例1:
// Node.js program to demonstrate the
// process.versions property
// Include process module
const process = require('process');
// Printing process.versions property value
console.log(process.versions);
輸出:
{ http_parser:'2.8.0', node:'10.16.0', v8:'6.8.275.32-node.52', uv:'1.28.0', zlib:'1.2.11', brotli:'1.0.7', ares:'1.15.0', modules:'64', nghttp2:'1.34.0', napi:'4', openssl:'1.1.1b', icu:'64.2', unicode:'12.1', cldr:'35.1', tz:'2019a' }
範例2:
// Node.js program to demonstrate the
// process.versions property
// Include process module
const process = require('process');
// Printing process.versions property value
// and variable count
var no_versions = 0;
// Calling process.versions property
var versions = process.versions;
// Itterating through all returned data
for (var key in versions) {
// Printing key and its versions
console.log(key + ":\t\t\t" + versions[key]);
no_versions++;
}
// Printing count value
console.log("Total no of values available = " + no_versions);
輸出:
http_parser: 2.8.0 node: 10.16.0 v8: 6.8.275.32-node.52 uv: 1.28.0 zlib: 1.2.11 brotli: 1.0.7 ares: 1.15.0 modules: 64 nghttp2: 1.34.0 napi: 4 openssl: 1.1.1b icu: 64.2 unicode: 12.1 cldr: 35.1 tz: 2019a Total no of values available = 15
範例3:
// Node.js program to demonstrate the
// process.versions property
// Include process module
const process = require('process');
// Calling process.versions property
var versions = process.versions;
// Printing one at a time
console.log("node version:" + versions.node);
console.log("openssl version:" + versions.openssl);
console.log("module versions:" + versions.modules);
輸出:
node version:10.16.0 openssl version:1.1.1b module versions:64
注意:上麵的程序將通過使用node filename.js
命令。
參考: https://nodejs.org/api/process.html#process_process_versions
相關用法
注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | process.versions Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。