Node.js process.release 属性
process.release 属性是 process 模块的内置应用程序编程接口,用于获取与 node.js 当前版本相关的元数据。
句法:
process.release
返回值:该属性返回一个包含当前 nodejs 版本元数据的对象。该对象将包含 name、sourceUrl、headersUrl、libUrl 和 lts 等属性。
- name:在 Node.js 中,name 的值将始终为 'node'。对于旧版 io.js 版本,它的值可以是 'io.js'。
- sourceUrl:它包含一个字符串,表示指向当前版本源代码的绝对 URL 作为 '.tar.gz' 文件。
- headersUrl:它包含一个字符串,表示指向当前发布源头文件的绝对 URL,如 '.tar.gz' 文件。该文件比源代码文件小,可用于编译 Node.js 原生插件。
- libUrl:它包含一个字符串,表示指向与当前版本的体系结构和版本匹配的“node.lib”文件的绝对 URL。该文件用于编译 Node.js 原生插件。此属性仅在 windows 版本中可用,在其他平台上可能会丢失。
- lts:代表最新稳定版本的字符串字面量。它的值可以是以下之一:
- Argon:适用于 4.xx LTS 版本
- Boron:适用于 6.xx LTS 版本
- Carbon:适用于 8.xx LTS 版本
- Dubnium:适用于 10.xx LTS 版本
下面的例子说明了在 Node.js 中process.release 属性的使用:
示例 1:
javascript
// Node.js program to demonstrate the
// process.release Property
// Include process module
const process = require('process');
// Printing process.release property value
console.log(process.release);
javascript
// Node.js program to demonstrate the
// process.release Property
// Include process module
const process = require('process');
// Printing process.release attribute count
var no_attr = 0;
// Calling process.release
var release = process.release;
// Iterating through all returned data
for (var key in release) {
// Printing key and its releases
console.log(key + ":\t\t\t" + release[key]);
no_attr++;
}
// Printing count
console.log("Total no of attribute "
+ "available = " + no_attr);
javascript
// Node.js program to demonstrate the
// process.release Property
// Include process module
const process = require('process');
// Calling process.release property
var release = process.release;
// Printing one data at a time
console.log("lts: " + release.lts);
console.log("source url: " + release.sourceUrl);
console.log("header url: " + release.headersUrl);
输出:
{ name: 'node',
lts: 'Dubnium',
sourceUrl:
'https://nodejs.org/download/release/v10.16.0/node-v10.16.0.tar.gz',
headersUrl:
'https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz',
libUrl:
'https://nodejs.org/download/release/v10.16.0/win-x64/node.lib' }
示例 2:
javascript
// Node.js program to demonstrate the
// process.release Property
// Include process module
const process = require('process');
// Printing process.release attribute count
var no_attr = 0;
// Calling process.release
var release = process.release;
// Iterating through all returned data
for (var key in release) {
// Printing key and its releases
console.log(key + ":\t\t\t" + release[key]);
no_attr++;
}
// Printing count
console.log("Total no of attribute "
+ "available = " + no_attr);
输出:
name: node
lts: Dubnium
sourceUrl: https://nodejs.org/download/release/v10.16.0/node-v10.16.0.tar.gz
headersUrl: https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz
libUrl: https://nodejs.org/download/release/v10.16.0/win-x64/node.lib
Total no of attribute available = 5
示例 3:
javascript
// Node.js program to demonstrate the
// process.release Property
// Include process module
const process = require('process');
// Calling process.release property
var release = process.release;
// Printing one data at a time
console.log("lts: " + release.lts);
console.log("source url: " + release.sourceUrl);
console.log("header url: " + release.headersUrl);
输出:
lts: Dubnium
source url: https://nodejs.org/download/release/v10.16.0/node-v10.16.0.tar.gz
header url: https://nodejs.org/download/release/v10.16.0/node-v10.16.0-headers.tar.gz
注意:上面的程序将使用 node filename.js 命令编译和运行。
参考: https://nodejs.org/api/process.html#process_process_release