This is the code that powers npmsearch.com, which provides a clean interface to searching pseudo-rated node packages from npm.
To query the npmsearch index, you can use the HTTP api which is effectively a proxy to elasticsearch's URI Search.
All requests go through http://npmsearch.com/query. Here's an example:
curl "http://npmsearch.com/query?q=dom&fields=name"
{"results":[{"name":["select-dom"]},{"name":["dom-manipulations"]},{"name":["zero-dom"]},{"name":["dom-stub"]},{"name":["dom-walk"]},{"name":["dom-value"]},{"name":["karma-chai-dom"]},{"name":["dom-select"]},{"name":["dom-listeners"]},{"name":["has-dom"]}],"total":7265,"from":0}
See the elasticsearch docs for setting up a node
# create an index
curl -XPUT http://localhost:9200/my-index-name
# setup the package field mappings
cat mappings.json | curl -v -XPOST http://localhost:9200/my-index-name/package/_mapping -H "Content-type: application/json" -d @-
# setup an alias to 'registry'
curl -XPOST 'http://localhost:9201/_aliases' -d '
{
"actions" : [
{ "add" : { "index" : "my-index-name", "alias" : "registry" } }
]
}'
npm2es --couch="https://skimdb.npmjs.com/registry" --es="http://localhost:9200/registry"
node bin/server.js --es="http://localhost:9200/registry"
node bin/rating.js --es="http://localhost:9200/registry"
Elijah Insua | GitHub/tmpvar | Twitter/@tmpvar |
---|
Authored by Elijah Insua. Contributions are welcomed from anyone wanting to improve this project!
npmsearch is Copyright (c) 2016 NodeSource and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.txt file for more details.
Search for packages npm search [-l|–long] [–json] [–parseable] [–no-description] [search terms …] aliases: s, se, find Search the registry for packages matching the search terms. npm search performs a
参考文章:npm常用命令 #启动nodeJs服务 node server.js Server running at http://127.0.0.1:8888/ #use #编译 $. npm run build #启动运行 $. npm run serve $. npm run start #-----------------------