gpt4 book ai didi

node.js - 哪些版本的 npm 附带了哪些版本的 Node?

转载 作者:太空宇宙 更新时间:2023-11-04 03:20:13 25 4
gpt4 key购买 nike

哪些版本的 npm 附带哪些版本的 Node ?我找不到这样的列表。

最佳答案

https://nodejs.org/dist/index.json它指示 Nodejs 的每个版本以及与其捆绑的 npm 版本。

<小时/>

index.json

index.json 数组中的一个对象的摘录如下:

[
{
"version": "v10.6.0", //<--- nodejs version
"date": "2018-07-04",
"files": [
...
],
"npm": "6.1.0", //<--- npm version
"v8": "6.7.288.46",
"uv": "",
"zlib": "1.2.11",
"openssl": "1.1.0h",
"modules": "64",
"lts": false
},
...
]

数组中的每个对象都有一个 version (即 Nodejs 版本)npm (即 npm 版本) 键/值对。

<小时/>

以编程方式获取版本

考虑使用以下 node.js 脚本从 https://nodejs.org/dist/index.json 端点请求数据。

获取版本.js

const { get } = require('https');

const ENDPOINT = 'https://nodejs.org/dist/index.json';


function requestVersionInfo(url) {
return new Promise((resolve, reject) => {
get(url, response => {
let data = '';
response.on('data', chunk => data += chunk);
response.on('end', () => resolve(data));
}).on('error', error => reject(new Error(error)));
});
}


function extractVersionInfo(json) {
return JSON.parse(json).map(({ version, npm = null }) => {
return {
nodejs: version.replace(/^v/, ''),
npm
};
});
}


(async function logVersionInfo() {
try {
const json = await requestVersionInfo(ENDPOINT);
const versionInfo = extractVersionInfo(json);
console.log(JSON.stringify(versionInfo, null, 2));

} catch ({ message }) {
console.error(message);
}
})();

运行以下命令:

node ./path/to/get-versions.js

将在您的控制台上打印如下内容:

[
{
"nodejs": "14.2.0",
"npm": "6.14.4"
},
{
"nodejs": "14.1.0",
"npm": "6.14.4"
},
{
"nodejs": "14.0.0",
"npm": "6.14.4"
},
{
"nodejs": "13.14.0",
"npm": "6.14.4"
},
...
]

如您所见,它列出了 Nodejs 的每个版本及其相应的 npm 版本。

关于node.js - 哪些版本的 npm 附带了哪些版本的 Node?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51238643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com