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

目标
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

 


 

转载于:https://www.cnblogs.com/soom/p/4417199.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值