转载

5 分钟搭建一个私有 npm registry

精华 5分钟搭建一个私有 npm registry

发布于 10小时前 作者fengmk2 233 次浏览 来自 分享

持续更新: https://github.com/cnpm/cnpmjs.org/wiki/Deploy-a-private-npm-registry-in-5-minutes

Install cnpmjs.org and cnpm from npm

$ npm install -g --build-from-source cnpmjs.org cnpm sqlite3 

If you’re in China, maybe you should use China mirror

$ npm install -g --build-from-source /   --registry=http://registry.npm.taobao.org /   --disturl=http://npm.taobao.org/mirrors/node   cnpmjs.org cnpm sqlite3 

Start cnpmjs.org server with configs

  • admins: myname,othername
  • scopes: my-company-name,other-name
  • default ports: 7001-registry, 7002-web
$ nohup cnpmjs.org start --admins='myname,othername' --scopes='@my-company-name,@other-name' & 

Change cnpm default registry to your private registry

$ cnpm set registry http://localhost:7001 

Use cnpm to login yourself on your private registry

$ cnpm login Username: myname Password: *** Email: (this IS public) m@fengmk2.com 

Publish your private package now!

Private package should be a scoped package

$ cd /tmp $ mkdir helloworld && cd helloworld $ cnpm init name: (helloworld) @my-company-name/helloworld version: (1.0.0)  {   "name": "@my-compny-name/helloworld",   "version": "1.0.0",   "description": "my first scoped package",   "main": "index.js",   "scripts": {     "test": "echo /"Error: no test specified/" && exit 1"   },   "author": "",   "license": "ISC" }  $ cnpm publish + @my-company-name/helloworld@1.0.0 

View your private package

You can visit with bowsers

$ open http://localhost:7002/@my-company-name/helloworld 

Or use cnpm info

$ cnpm info 

All public packages available directly

You can install all public packages from npmjs.org

$ cnpm install mocha 
7 回复
5 分钟搭建一个私有 npm registry

i5ting 1楼•3小时前

亲,node modules在本地安装次数太多了,有更好的办法么?

-g 不算

5 分钟搭建一个私有 npm registry

fengmk2 2楼•2小时前

@i5ting 没太看明白,是说依赖太多了?

5 分钟搭建一个私有 npm registry

i5ting 3楼•1小时前

@fengmk2 不是这个意思 ,是说重复依赖依赖

比如一个项目基于express,他会有debug,cookie等

但是再express-session里也有,这样的重复太不经济了

5 分钟搭建一个私有 npm registry

microlv 4楼•1小时前

@i5ting 这个应该正常吧,就算是你写nodejs,你的引用也会用到相对目录或上级目录。如:

require('./xx'),require('../xx') 

不重复怎样保证路径正确。你又不能修改别人的npm模块。总不能全部-g吧

5 分钟搭建一个私有 npm registry

karlsun 5楼•1小时前

@i5ting @fengmk2 应该是说,多个项目使用相同的module,但是每次都安装么?环境一样,直接cp算不算,我看npm也有缓存,装一下不费事 >.<

5 分钟搭建一个私有 npm registry

karlsun 6楼•1小时前

@i5ting @fengmk2 哦,理解错误~那样是感觉不爽~

5 分钟搭建一个私有 npm registry

karlsun 7楼•1小时前

@alsotang 页面几十分钟没刷,没看到LZ的回复,想当然的回复了错误的理解。要是在评论有增加时,自动推送就好了。

正文到此结束
Loading...