我发现我经常对https://www.npmjs.com/上的搜索顺序和表现力不满意。我想应该有一种方法可以使用https://api.npmjs.org/或http://registry.npmjs.org/以编程方式查询服务器。但是怎么样?文件在哪里?
(或者是否有节点包来促进这一点?我知道SO不是关于工具或包装推荐的,所以也许我也不应该问这个问题,但如果有一些工具,我可能也可以从中读取API。)
答案 0 :(得分:19)
当然,至少有一个工具可以与该注册表进行通信,这就是npm
命令行工具本身。例如,它的search首先更新索引的本地缓存副本,然后对其进行过滤。在update-index中,可以看到以/-/all
结尾的网址显然是特殊的。事实上,将其附加到registry.npmjs.org
(故意不格式化为链接)将获取125M文件,这可能对您的浏览器来说太多了。幸运的是,缓存版本存储在~/.npm/registry.npmjs.org/-/all/.cache.json
中。从那里可以读取所有已知包的列表。然后,可以继续更详细地查询每个这样的包。
npm search
显然没有使用更复杂的方案这一事实表明这里没有太多的服务器端api。
在网页上搜索提到api.npmjs.org
的网页时,我发现可以从那里检索download counts。我找到的所有其他文件都使用了这一单一设施。
寻找替代方案,我偶然发现npmsearch.com提供了一些更多功能的搜索工具,并a somewhat documented API。
答案 1 :(得分:12)
您始终可以使用NPM注册表客户端:https://github.com/npm/npm-registry-client。
如果仔细观察,可以获得API的端点。 例如,为了得到包的dist-tag,你可以去/ - / package / packageName / dist-tags'
因此,要获得babel-core dist标记,您需要转到http://registry.npmjs.org/-/package/babel-core/dist-tags
答案 2 :(得分:11)
最近发现了一个非常好的npm查询网站https://npms.io。 他们还根据各种数据为每个包装提供质量点系统。
他们还将使用收集的有关项目的信息为每个包提供评分系统。最终得分是根据质量,维护,受欢迎程度和个性的四个不同方面计算的。
API文档:https://api-docs.npms.io
答案 3 :(得分:5)
https://skimdb.npmjs.com/registry/_all_docs
这是拉取所有包名的当前方法。
网址搜索为http://registry.npmjs.com/-/v1/search?text=<searchstring>&size=20
答案 4 :(得分:3)
看看sinopia注册表界面:https://github.com/rlidwka/sinopia/blob/master/lib/index-api.js。 npm客户端的默认注册表是https://registry.npmjs.org(在控制台上试用:npm config ls -l)。因此,您可以尝试以下(引用sinopia API)来获取有关react 15.0.2的数据
答案 5 :(得分:3)
我知道这个答案很旧,但是有些人仍然可以找到它的相关性,
经过大量搜索,我终于找到了一些东西,该解决方案不使用NPM API,因为它的文档不好,而且有很多缺点
(这对搜索以外的其他用途很有帮助,例如搜索流行的软件包列表(我需要))
解决方案是使用Libraries.io
Libraries.io为来自36个程序包管理器的4,273,741个程序包中的数据建立索引。 (包括NPM) 来自Libraries.io page
它具有出色的API和良好的文档,还提供了几种语言的API包装器
您可以看一下使用该库here的CLI程序
答案 6 :(得分:3)
您可以在以下GitHub存储库中找到官方NPM注册表API的官方文档:https://github.com/npm/registry
搜索端点的文档可以在这里找到:https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search
可接受以下查询参数:文本,大小,质量,受欢迎程度,维护
curl -sL 'https://registry.npmjs.org/-/v1/search?text=react-native&size=5' | jq
在这里,我们使用curl
发出API请求,并使用jq
格式化JSON响应。返回以下输出:
{
"objects": [
{
"package": {
"name": "react-native",
"scope": "unscoped",
"version": "0.62.2",
"description": "A framework for building native apps using React",
"date": "2020-04-08T17:08:19.985Z",
"links": {
"npm": "https://www.npmjs.com/package/react-native",
"homepage": "https://github.com/facebook/react-native#readme",
"repository": "https://github.com/facebook/react-native",
"bugs": "https://github.com/facebook/react-native/issues"
},
"publisher": {
"username": "react-native-bot",
"email": "opensource+react-native-bot@fb.com"
},
"maintainers": [
{
"username": "cpojer",
"email": "christoph.pojer@gmail.com"
},
{
"username": "fb",
"email": "opensource+npm@fb.com"
},
{
"username": "grabbou",
"email": "grabbou@gmail.com"
},
{
"username": "hectorramos",
"email": "hector@hectorramos.com"
},
{
"username": "react-native-bot",
"email": "opensource+react-native-bot@fb.com"
}
]
},
"flags": {
"unstable": true
},
"score": {
"final": 0.4604636166574407,
"detail": {
"quality": 0.5886895871400879,
"popularity": 0.47768592528213616,
"maintenance": 0.3333333333333333
}
},
"searchScore": 100000.47
},
{
"package": {
"name": "react-native-svg",
"scope": "unscoped",
"version": "12.1.0",
"description": "SVG library for react-native",
"keywords": [
"react-component",
"react-native",
"ios",
"android",
"SVG",
"ART",
"VML",
"gradient"
],
"date": "2020-04-09T23:50:28.358Z",
"links": {
"npm": "https://www.npmjs.com/package/react-native-svg",
"homepage": "https://github.com/react-native-community/react-native-svg",
"repository": "https://github.com/react-native-community/react-native-svg",
"bugs": "https://github.com/react-native-community/react-native-svg/issues"
},
"publisher": {
"username": "msand",
"email": "msand@abo.fi"
},
"maintainers": [
{
"username": "brentvatne",
"email": "brentvatne@gmail.com"
},
{
"username": "dustin.savery",
"email": "dustin.savery@gmail.com"
},
{
"username": "magicismight",
"email": "master@horcrux.cn"
},
{
"username": "msand",
"email": "msand@abo.fi"
}
]
},
"score": {
"final": 0.5244501419238121,
"detail": {
"quality": 0.9582364654638059,
"popularity": 0.34375010176572474,
"maintenance": 0.3333333333333333
}
},
"searchScore": 0.031369504
},
{
"package": {
"name": "react-native-device-info",
"scope": "unscoped",
"version": "5.6.1",
"description": "Get device information using react-native",
"keywords": [
"react-component",
"react-native",
"ios",
"android",
"windows",
"device",
"events",
"cocoapod"
],
"date": "2020-05-27T18:33:11.715Z",
"links": {
"npm": "https://www.npmjs.com/package/react-native-device-info",
"homepage": "https://github.com/react-native-community/react-native-device-info#readme",
"repository": "https://github.com/react-native-community/react-native-device-info",
"bugs": "https://github.com/react-native-community/react-native-device-info/issues"
},
"author": {
"name": "Rebecca Hughes",
"email": "rebecca@learnium.net",
"url": "https://github.com/rebeccahughes"
},
"publisher": {
"username": "mikehardy",
"email": "npmjs@mikehardy.net"
},
"maintainers": [
{
"username": "gantman",
"email": "gantman+npm@gmail.com"
},
{
"username": "jeroenbourgois",
"email": "info@jeroenbourgois.be"
},
{
"username": "lilach",
"email": "i.am.red@gmail.com"
},
{
"username": "machour",
"email": "machour@gmail.com"
},
{
"username": "rebeccahughes",
"email": "rebeccahughes1@outlook.com"
}
]
},
"score": {
"final": 0.5102794746987024,
"detail": {
"quality": 0.9614895473985808,
"popularity": 0.3004741251784613,
"maintenance": 0.3333333333333333
}
},
"searchScore": 0.016712856
},
{
"package": {
"name": "css-to-react-native",
"scope": "unscoped",
"version": "3.0.0",
"description": "Convert CSS text to a React Native stylesheet object",
"keywords": [
"styled-components",
"React",
"ReactNative",
"styles",
"CSS"
],
"date": "2019-10-10T17:46:00.297Z",
"links": {
"npm": "https://www.npmjs.com/package/css-to-react-native",
"homepage": "https://github.com/styled-components/css-to-react-native#readme",
"repository": "https://github.com/styled-components/css-to-react-native",
"bugs": "https://github.com/styled-components/css-to-react-native/issues"
},
"author": {
"name": "Jacob Parker"
},
"publisher": {
"username": "jacobp100",
"email": "jacobparker1992@gmail.com"
},
"maintainers": [
{
"username": "jacobp100",
"email": "jacobparker1992@gmail.com"
},
{
"username": "kristerkari",
"email": "krister@sent.at"
},
{
"username": "mxstbr",
"email": "npm@mxstbr.com"
}
]
},
"score": {
"final": 0.4836548888489432,
"detail": {
"quality": 0.8524860977159072,
"popularity": 0.39264581380833835,
"maintenance": 0.25852292771786467
}
},
"searchScore": 0.013077582
},
{
"package": {
"name": "react-native-elements",
"scope": "unscoped",
"version": "2.0.4",
"description": "React Native Elements & UI Toolkit",
"keywords": [
"react-native",
"reactjs",
"reactnative",
"bootstrap"
],
"date": "2020-06-30T02:30:34.882Z",
"links": {
"npm": "https://www.npmjs.com/package/react-native-elements",
"homepage": "https://react-native-elements.github.io/react-native-elements/",
"repository": "https://github.com/react-native-elements/react-native-elements",
"bugs": "https://github.com/react-native-elements/react-native-elements/issues"
},
"author": {
"name": "Nader Dabit & Monte Thakkar"
},
"publisher": {
"username": "flyingcircle",
"email": "jeremyelijah@live.com"
},
"maintainers": [
{
"username": "dabit3",
"email": "dabit3@gmail.com"
},
{
"username": "iroachie",
"email": "kroach.work@gmail.com"
},
{
"username": "monte9",
"email": "mthakkar@mail.sfsu.edu"
}
]
},
"score": {
"final": 0.4921277780507845,
"detail": {
"quality": 0.9218028296308819,
"popularity": 0.28262932141386665,
"maintenance": 0.3333333333333333
}
},
"searchScore": 0.011005878
}
],
"total": 26290,
"time": "Wed Jul 08 2020 05:02:14 GMT+0000 (UTC)"
}
答案 7 :(得分:2)
如果找不到软件包,或者只是一起破解shell脚本,则注册表Registry API Docs中的git repository包含有关Search API和搜索限定符的详细信息。
如果要在公共注册表中查找最流行的不安全软件包,请运行:
wget -qO - "http://registry.npmjs.com/-/v1/search?text=is:insecure&popularity=1.0&size=1"
上面的代码使用is:insecure
搜索限定符,没有任何其他文本条件,并在size=1
(最受欢迎的位置)中获取popularity=1.0
的结果。
在回购中的docs
directory中检查许多其他有用的东西,例如:
答案 8 :(得分:1)
您可以使用api-npm节点模块直接查询NPM注册表,您可以获取模块的所有属性并下载任何时间范围的任何模块的统计信息 https://www.npmjs.com/package/api-npm
答案 9 :(得分:1)
文档现在在这里: https://github.com/npm/registry/blob/master/docs/download-counts.md
获取给定时间段内所有软件包或特定软件包的总下载量。
GET https://api.npmjs.org/downloads/point/{period}[/{package}]