前端全栈

搭建私有npm服务器教程

2019-02-23  本文已影响103人  code追命

私有npm服务器搭建

标签(空格分隔): Node.js


私有npm服务器搭建

本次搭建是在ubuntu环境下搭建的,如果其他系统,将个别命令改成自己的

# clone from github
$ git clone git://github.com/cnpm/cnpmjs.org.git $HOME/cnpmjs.org
$ cd $HOME/cnpmjs.org

sudo apt install mysql-server

中间会提示设置root 账户的密码
有的文章提到 还要 install mysql-client 现在不需要了,已经包含了

sudo netstat -tap | grep mysql

出现如下信息证明安装成功:

image
# create mysql tables
$ mysql -u yourname -p
mysql> create database cnpmjs;
mysql> use cnpmjs;
mysql> source docs/db.sql;

config目录下创建config.js文件。(默认只有index.js文件)。在config.js中添加一下配置

config.js文件会直接覆盖index.js中的默认配置

 module.exports = {
    debug: false,
    enableCluster: true, // enable cluster mode
    enablePrivate: true, // enable private mode, only admin can publish, other use just can sync package from source npm
    database: {
        db: 'cnpmjstest',
        host: 'localhost',
        port: 3306,unknown database cnpmjs
        username: 'cnpmjs',
        password: 'cnpmjs123'  
    },
    admins: {
      admin: 'admin@cnpmjs.org',
    },
    syncModel: 'exist'// 'none', 'all', 'exist',
    sourceNpmRegistry:"http://127.0.0.1/",
    registryHost: '127.0.0.1:7001',
  };  

注意

npm run start

在本地访问http://localhost:/7001

显示

{"data_tables":{},"disk_size":0,"data_size":0,"index_size":0,"disk_format_version":0,"committed_update_seq":0,"update_seq":0,"purge_seq":0,"compact_running":false,"doc_count":0,"doc_del_count":0,"doc_version_count":0,"user_count":0,"sync_status":0,"need_sync_num":0,"success_sync_num":0,"fail_sync_num":0,"left_sync_num":0,"last_sync_time":0,"last_exist_sync_time":0,"last_sync_module":"","download":{"today":0,"thisweek":0,"thismonth":0,"lastday":0,"lastweek":0,"lastmonth":0},"db_name":"registry","instance_start_time":"1521614106548","node_version":"v4.2.6","app_version":"3.0.0-beta.1","donate":"https://www.gittip.com/fengmk2","sync_model":"exist","cache_time":1521615310970}

访问http://localhost:7002.显示cnpm界面。说明安装和运行成功

上传自己的npm包到私有cnpm服务器

sudo npm i cnpm -g

cnpm adduser --registry=http://127.0.0.1:7001/

cnpm login --registry=http://127.0.0.1:7001/

npm init test -y

name:'test'  改为  name:'@cnpm/test'

cnpm publish --registry=http://127.0.0.1:7001/

cnpm i @cnpm/test --registry=http://127.0.0.1:7001/

nrm管理多个npm

sudo npm i nrm -g

nrm add localnpm http://127.0.0.1:7001

上一篇下一篇

猜你喜欢

热点阅读