资讯专栏INFORMATION COLUMN

在linux Ubuntu创建npm私有库

dongfangyiyu / 1051人阅读

摘要:

Our server environment is linux Ubuntu, this article is mainly about how to build our NPM private library in linux Ubuntu environment.

Install Nodejs

We need to use the npm command to install verdaccio, so first we have to have a node environment.

Step1– Add Node.js PPA
$ sudo apt-get install software-properties-common
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Step 2 – Install Node.js on Ubuntu
$ sudo apt-get install nodejs
Step 3 – Check Node.js and NPM Version

After installing node.js verify and check the installed version.

$ node -v

v12.2.0

Also, check the npm version

$ npm -v
v6.9.0
Install verdaccio
$ 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:

If we install successfull, we can see the result

/usr/bin/verdaccio -> /usr/lib/node_modules/verdaccio/bin/verdaccio
+ verdaccio@3.11.7
Start verdaccio
$ verdaccio

The results are as follows:

 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 /home/npm/.config/verdaccio/config.yaml and the default access address is http://localhost:4873/

Modify the config

access to the config.yaml file

$ 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:

# you can specify listen address (or simply a port)
listen: 0.0.0.0:8080

View detailed verdaccio profile documentation

Start verdaccio with command verdaccio
$ verdaccio
Access to a built private repository

Open http://[ip address]:8080 in the browser, if it can be accessed normally, it means that the construction is successful.
Our ip address is 104.43.246.39,open http://104.43.246.39:8080,we can see the interface like below:

notice: 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.

Start verdaccio with pm2 to ensure that the process is always open

we can also start verdaccio with pm2 to ensure that the process is always open.And we can get more detail.

Install pm2
$ npm install -g pm2 --unsafe-perm=true --allow-root
Start verdaccio with pm2
$ pm2 start verdaccio
stop verdaccio with pm2
$ pm2 stop verdaccio
Let verdaccio run in the background

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.

run verdaccio in 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...!
Client publishes npm to private repository

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
Npm successfully released to private repository

Refresh the http://104.43.246.39:8080 page in the browser, as shown in the figure:

How to use the private repository npm package Step1- change the npm registry address
npm set registry http://104.43.246.39:8080
Step2- Install package
npm install @sfc/example

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/109549.html

相关文章

  • Flux7 Docker 系列教程(一):Docker 简介

    摘要:本系列教程翻译自,系列共有九篇,本文译自第一篇。,一种新的容器化技术,因为轻量级和便携化而受到广泛关注。本篇文章是系列教程的第一篇。镜像只读的容器模板,简言之就是系统镜像文件。首先,向发出请求创建一个镜像并且指定容器内要运行的命令。 本系列教程翻译自 Flux7 Docker Tutorial Series,系列共有九篇,本文译自第一篇 Part 1: An Introduction。...

    zhaofeihao 评论0 收藏0
  • Flux7 Docker 系列教程(一):Docker 简介

    摘要:本系列教程翻译自,系列共有九篇,本文译自第一篇。,一种新的容器化技术,因为轻量级和便携化而受到广泛关注。本篇文章是系列教程的第一篇。镜像只读的容器模板,简言之就是系统镜像文件。首先,向发出请求创建一个镜像并且指定容器内要运行的命令。 本系列教程翻译自 Flux7 Docker Tutorial Series,系列共有九篇,本文译自第一篇 Part 1: An Introduction。...

    yacheng 评论0 收藏0
  • 可能是最详细的部署:Docker Registry企业级私有镜像仓Harbor管理WEB UI

    摘要:私有仓库是,并在中运行。不要使用或为主机名注册表服务需要由外部客户端访问或,默认为用于访问和令牌通知服务的协议。打开或关闭,默认打开打开此属性时,准备脚本创建私钥和根证书,用于生成验证注册表令牌。 上一篇文章搭建了一个具有基础功能,权限认证、TLS 的私有仓库,但是Docker Registry 作为镜像仓库,连管理界面都没有,甚至连一些运维必备的功能都是缺失的,还有什么 Docker...

    沈俭 评论0 收藏0
  • Docker Registry Server 搭建,配置免费HTTPS证书,及拥有权限认证、TLS

    摘要:上一篇文章搭建了一个具有基础功能的私有仓库,这次来搭建一个拥有权限认证的私有仓库。移动证书到目录。身份验证为用户创建一个带有一个条目的密码文件,密码为创建仓库启动注册表,指示它使用证书。注册表在端口默认的端口上运行。 上一篇文章搭建了一个具有基础功能的私有仓库,这次来搭建一个拥有权限认证、TLS 的私有仓库。 环境准备 系统:Ubuntu 17.04 x64 IP:198.13.48...

    liuchengxu 评论0 收藏0
  • 全栈工程师之路——服务器端自动部署

    摘要:如果你想要成为一名全栈工程师,那么就必须要学会,学会线上服务器部署和发布。准备为了避免个人花钱买云服务器。用户名必须正确,否则会提示服务器拒绝密码。还有一个这个是自动部署需要的,目录结构如下这文件的配置很重要。 前言 作为一名前端工程师,不仅要能写前端页面,还要懂前端工程,各种库,各种框架,各种衍生语言,信手捏来。如果你想要成为一名全栈工程师,那么就必须要学会Node.js,学会线上服...

    OpenDigg 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<