使用sinopia這個(gè)工具,主要是做為一個(gè)內(nèi)網(wǎng)虛擬機(jī)的中轉(zhuǎn)站同辣,具體是因?yàn)殚_(kāi)發(fā)需求不能在虛擬機(jī)內(nèi)訪問(wèn)internet弯屈,那么,我要加載node模塊怎么辦献汗,當(dāng)然sinopia不僅只是做一個(gè)中轉(zhuǎn)站敢订,還可以發(fā)布自己的私人node包,這個(gè)也有助于內(nèi)網(wǎng)使用罢吃。
說(shuō)下原理:
1楚午、npmjs.com
2、npm.taobao.com
3尿招、可訪問(wèn)互聯(lián)網(wǎng)的內(nèi)網(wǎng)server(安裝sinopia)
4矾柜、client(請(qǐng)求node包)
具安裝步驟:
1阱驾、安裝node 環(huán)境(建議8.x 因?yàn)槭褂?0.x的時(shí)候有sinopia報(bào)錯(cuò))
... 省略
2、npm下載sinopia
$ npm install -g sinopia
//或者使用cnpm(使用taobao鏡像工具) **推薦**
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
$ cnpm install -g sinopia
3怪蔑、配置 sinopia
參考自 #使用Sinopia搭建私有的npm倉(cāng)庫(kù)
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/rlidwka/sinopia/tree/master/conf
#
# path to a directory with all packages
storage: ./storage #npm包存放的路徑
auth:
htpasswd:
file: ./htpasswd #保存用戶的賬號(hào)密碼等信息
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
max_users: -1 #默認(rèn)為1000里覆,改為-1,禁止注冊(cè)
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: http://registry.npm.taobao.org/ #默認(rèn)為npm的官網(wǎng)缆瓣,由于國(guó)情喧枷,修改 url 讓sinopia使用 淘寶的npm鏡像地址
packages: #配置權(quán)限管理
'@*/*':
# scoped packages
access: $all
publish: $authenticated
'*':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
# you can specify listen address (or simply a port)
listen: 0.0.0.0:4873 #//默認(rèn)沒(méi)有,只能在本機(jī)訪問(wèn)弓坞,添加后可以通過(guò)外網(wǎng)訪問(wèn)隧甚。
4、啟動(dòng) sinopia
sinopia
$ sinopia
5渡冻、客戶端配置
參考自國(guó)內(nèi)npm鏡像及配置方法
//注冊(cè)ip
npm config set registry http://192.168.1.200:4873
// 配置后可通過(guò)下面方式來(lái)驗(yàn)證是否成功
npm config get registry
// 或
npm info express