There is a server from the backend, and there is nothing on it. I want to build an npm privatized warehouse to put some public components of the company's project, as well as the project's SDK, and make the library into the project to use. That's it.

First log in to the server,

Set up the environment

The first step is to install nodejs

yum install -y epel-release
yum install -y nodejs

node -v Check it out

The good guy version is so low! Only 6.17.1
Upgrade the version, install the nodejs package management tool

npm install -g n

Some commonly used commands:

n stable // 把当前系统的 Node 更新成最新的 “稳定版本”
n lts // 长期支持版
n latest // 最新版
n 10.14.2 // 指定安装版本
n  // 查看已安装的版本
n rm 10.14.2  // 删除指定版本

n command line and press Enter

Select a version and press enter again
node -v again, the version shows that v6.17.1 switched, why there is no change!

Baidu, found that the current version is not the latest version, and then has installed the latest version, the reasons for not taking effect:
The default installation directory of node is inconsistent with the directory installed using the management tool n.

Solution:
View the current node installation path

which node

And n is the default installation path /usr/local , current node installation path and n path inconsistent need by N_PREFIX to modify the default installation path node n variables.

Edit the environment configuration file: vim ~/.bash_profile

Modify node installation location: add export PATH=/usr/local/bin:$PATH shift+:wq at the end to save and exit

Let the new configuration take effect: source ~/.bash_profile

Reinstall the stable version: n stable

Check the current node version: node -v (it is already the latest stable version)

Okay, you can start business, install verdaccio !

Install verdaccio

npm i -g verdaccio

verdaccio command line and press Enter to start verdaccio , you can see the configuration file address on the first line:

config file  - /root/.config/verdaccio/config.yaml

listen: 0.0.0.0:4873 the last line of the configuration file. If there is no such line by default, it can only be accessed on the local machine. After adding, it can be accessed through the external network.

pm2 guards the verdaccio process

  1. Install pm2
    npm install -g pm2
  2. Use pm2 to start verdaccio
    pm2 start verdaccio
  3. View the real-time log of the process verdaccio under the pm2 daemon
    pm2 show verdaccio
  4. View the log commands under this path in real time
    tail -f /home/admin/.pm2/logs/verdaccio-out-0.log

There are several commands commonly used in the configuration process

netstat -tunlp  // 查看所有的端口进程
netstat -tunlp|grep 端口号  // 查看指定的端口号
kill 端口号  // 杀死指定的端口号进程
telnet ip地址 端口号  // telnet需要安装, 查看该地址 该端口是否被使用
// 例如
telnet localhost 4873
telnet 192.168.0.1 4873

At this time, the server is configured. For example, the address of the server is 192.168.0.1 http://192.168.0.1:4873 in our browser normally (the port must be added and the firewall must be closed!)

Manage source release packages

Next we will publish the package to our privatized warehouse!
First install a tool for npm nrm

npm i nrm -g
nrm list 或者 nrm ls // 查看源列表
nrm add [name] [源url]  // 添加源
nrm use [name]  // 使用源
nrm del [name]  // 删除源

Use nrm use switch to the address of the newly created privatized warehouse
log in:

npm whoami // 查看当前登录用户
npm adduser --registry http://yourip:4873/

release

npm publish --registry http://yourip:4873/
// 如果你切换到当前源了 直接 npm publish 即可

Then refresh to see the package you released!

Update package:

1. 修改package.json version字段的版本号
2. 命令行:npm publish

reference:
https://verdaccio.org/docs/zh-cn/installation
is still a problem with the original version after upgrading node
Linux install telnet
https://www.cnblogs.com/kunmomo/p/11221786.html


高压郭
961 声望494 粉丝

从简单到难 一步一步