ubuntu npm 私有库搭建 (npmjs.org 官方版本)
异步 同步官方nodejs模块 (可以不做)
npm curl -X POST http://127.0.0.1:5984/_replicate -d ‘{"source":"http://registry.npmjs.org/registry/", "target":"registry", "continuous":true, "create_target":true}‘ -H "Content-Type: application/json"
2.修改配置
/usr/local/etc/couchdb/local.ini [couch_httpd_auth] public_fields = appdotnet, avatar, avatarMedium, avatarLarge, date, email, fields, freenode, fullname, github, homepage, name, roles, twitter, type, _id, _rev users_db_public = true [httpd] bind_address = 0.0.0.0 secure_rewrites = false [couchdb] delayed_commits = false [admins] admin = password
3.上传npm程序
git clone git://github.com/npm/npm-registry-couchapp cd npm-registry-couchapp sudo npm install -g couchapp npm install npm start --npm-registry-couchapp:couch=http://admin:password@localhost:5984/registry npm run load --npm-registry-couchapp:couch=http://admin:password@localhost:5984/registry npm run copy --npm-registry-couchapp:couch=http://admin:password@localhost:5984/registry couchapp push www/app.js http://admin:password@localhost:5984/registry
这边推上去的两个程序访问地址:
http://localhost:5984/_utils/registry/_design/app/_rewrite
然后只需将registry指向couchdb即可操作私有npm库:
npm --registry http://localhost:5984/registry/_design/app/_rewrite login npm --registry http://localhost:5984/registry/_design/app/_rewrite publish my-repo
私有npm到这里就建好了,链接好长!
于是在/usr/local/etc/couchdb/default.ini文件中添加:
[vhosts] 127.0.0.1:5984=/registry/_design/app/_rewrite 127.0.0.2:5984=/registry/_design/ui/_rewrite
这回我们可以用http://127.0.0.1:5984来代替那串长长的链接了
接着就是将私有npm库没有的模块(返回404)通过npmjs.org找,于是写nginx配置如下:
server { listen 80; server_name npm.XXX.com; location / { proxy_set_header Host 127.0.0.1:5984; proxy_pass http://127.0.0.1:5984; proxy_intercept_errors on; error_page 404 = @fallback; } location @fallback{ internal; proxy_set_header Host registry.npmjs.org; proxy_pass http://registry.npmjs.org; } } server { listen 80; server_name npmui.XXX.com; location / { proxy_set_header Host 127.0.0.2:5984; proxy_pass http://127.0.0.2:5984; } }
registry=http://npm.XXX.com/
就可以使用我们的私有库了
npm login #登录 admin password #进入我们的私有包目录 完善package.json 然后 npm publish #删除的话是 npm unpublish ***@0.0.0
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。