码迷,mamicode.com
首页 > Web开发 > 详细

ubuntu npm 私有库搭建 (npmjs.org 官方版本)

时间:2015-04-11 11:44:37      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:

目标
npm.xxx.com 安装和推送nodejs包
npmui.xxx.com 管理已经推送的nodejs包
 
安装 couchdb
 
https://launchpad.net/~couchdb/+archive/ubuntu/stable
 
里面有 14.10  14.04 和 12.04的   PPA地址 安装不在这里讨论
 
安装 couchdb 1.6.1
 
1.初始化
 
访问“http://localhost:5984/_utils/”
新建名字为  registry 库
 
异步 同步官方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

http://localhost:5984/_utils/registry/_design/ui/_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;
    }
}
 
写在最后
到这里我们的私有库已经搭建完成了
我们可以在 ~/.npmrc 中添加
 
registry=http://npm.XXX.com/

就可以使用我们的私有库了

npm login 
#登录  admin password
#进入我们的私有包目录 完善package.json 然后
npm publish
#删除的话是 
npm unpublish  ***@0.0.0

 


 

ubuntu npm 私有库搭建 (npmjs.org 官方版本)

标签:

原文地址:http://www.cnblogs.com/soom/p/4417199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!