Our server environment is linux Ubuntu, this article is mainly about how to build our NPM private library in linux Ubuntu environment.node
We need to use the npm command to install verdaccio, so first we have to have a node environment.linux
$ sudo apt-get install software-properties-common $ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install nodejs
After installing node.js verify and check the installed version.npm
$ node -v v12.2.0
Also, check the npm versionjson
$ npm -v v6.9.0
$ sudo npm install -g verdaccio --unsafe-perm=true --allow-root
Add the --unsafe-perm=true --allow-root option to prevent gyp ERR! permission denied permission error like below:vim
If we install successfull, we can see the resultbash
/usr/bin/verdaccio -> /usr/lib/node_modules/verdaccio/bin/verdaccio + verdaccio@3.11.7
$ verdaccio
The results are as follows:app
warn --- config file - /home/npm/.config/verdaccio/config.yaml warn --- Plugin successfully loaded: htpasswd warn --- Plugin successfully loaded: audit warn --- http address - http://localhost:4873/ - verdaccio/3.11.7
From the output of the console, we can see that verdaccio's configuration file path is in <font color="#00asdd">/home/npm/.config/verdaccio/config.yaml</font > and the default access address is http://localhost:4873/curl
access to the config.yaml fileui
$ cd /home/npm/.config/verdaccio/ $ ls config.yaml htpasswd storage $ vim config.yaml
Add the code at the end of the configuration file config.yaml:this
# you can specify listen address (or simply a port) listen: 0.0.0.0:8080
View detailed verdaccio profile documentation
$ verdaccio
Open http://<font color="00aadd">[ip address]</font>:8080 in the browser, if it can be accessed normally, it means that the construction is successful.
Our ip address is <font color="00aadd">104.43.246.39</font>,open http://104.43.246.39:8080,we can see the interface like below:
<font color="ff0000">notice:</font> Add a security group to the cloud server and open the 8080 port number.
If the port security group is not added, you cannot access the http://104.43.246.39:8080 in the browser.
we can also start verdaccio with pm2 to ensure that the process is always open.And we can get more detail.
$ npm install -g pm2 --unsafe-perm=true --allow-root
$ pm2 start verdaccio
$ pm2 stop verdaccio
If you connect to the linux server via putty SSH, when the terminal becomes inactive and the process dies. So we need to run the verdaccio in the background.
$ screen $ verdaccio
stop the process in background
$ screen ls There are screens on: 16129.pts-0.VM-NPM (05/15/19 09:31:04) (Detached) 15809.pts-2.VM-NPM (05/15/19 09:28:43) (Detached) $ screen -r 16129.pts-0.VM-NPM npm@VM-NPM:/var/www/app$ node server.js Server started on localhost:8080; press Ctrl-C to terminate...!
After using verdaccio to build a private repository on the server, the next step is how to upload the npm package to the private repository server locally.
you need to register or login your account. If we don't have an account yet, we can create it by entering the command npm adduser --registry http://104.43.246.39:8080 and then entering the username in turn. If you already have an account, you can log in by entering the command npm login --registry http://104.43.246.39:8080 and then entering the username and password. Then enter the code directory we need to upload, execute the command to publish.
You must first register an account before publishing the npm package.
npm adduser --registry http://104.43.246.39:8080 Username: jane Password: Email: (this IS public) 924902324@qq.com Logged in as jane on http://104.43.246.39:8080.
The output Logged in as jane on http://104.43.246.39:8080., indicating that the npm account jane successfully logged into the http://104.43.246.39:8080 private repository.
Just got a project name called 'example', there is nothing in it, npm init creates a new package.json.
npm init
npm publish --registry http://104.43.246.39:8080
Refresh the http://104.43.246.39:8080 page in the browser, as shown in the figure:
npm set registry http://104.43.246.39:8080
npm install @sfc/example