process.version屬性是Process模塊的內置應用程序編程接口,用於檢查node.js版本。
用法:
process.version
返回:它返回一個表示Node.js版本的字符串。
以下示例說明了Node.js中process.version屬性的用法:
範例1:
// Allocating process module
const process = require('process');
// Printing process.version
console.log("node.js version " + process.version);
輸出:
node.js version v10.16.0
範例2:
// Allocating process module
const process = require('process');
// Printing process.version
const ver = process.version;
console.log("node.js version " + ver);
// Printing version name
var name = "";
if(ver.startsWith('v10.')) {
name = 'Dubnium';
}else if(ver.startsWith('v8.')) {
name = 'Caron';
}else if(ver.startsWith('v6.')) {
name = 'Boron';
}else if(ver.startsWith('v4.')) {
name = 'Argon';
}else {
name = 'unknown';
}
console.log("Node.js version name:" + name);
輸出:
node.js version v10.16.0 Node.js version name:Dubnium
參考: https://nodejs.org/api/process.html#process_process_version
相關用法
注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | process.version Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。