在linux Ubuntu创建npm私有库

2019-05-16 admin

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 <font color="#00asdd">/home/npm/.config/verdaccio/config.yaml</font > 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://&lt;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.

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://segmentfault.com/a/1190000019203170

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-65122.html

文章标题:在linux Ubuntu创建npm私有库

相关文章
js+html5实现可在手机上玩的拼图游戏
本文实例讲述了js+html5实现可在手机上玩的拼图游戏。分享给大家供大家参考。具体如下: 手机版的拼图。pc上用Chrome 或者 Firefox var R=(function(){ &#x2F;*右边菜单*&#x2F; functi...
2017-03-27
js面向对象之公有、私有、静态属性和方法详解
现下,javascript大行其道,对于网站开发人员来说,javascript是必需掌据的一门语言,但随着jquery等框架的流行和使用,许多人对于原生javascript缺乏深入的理解,习惯了函数式的编辑风格,对于闭包、原型总是说不清道不...
2017-03-22
为什么 JavaScript 会在移动端中胜出?
JavaScript并不是世界上最优美的编程语言。正因如此,一个世界级的专家写了一本关于这个语言的“精粹 ”的书。这本书的名字是“深度挖掘javascript的亮点”,因为优秀的东西被埋的相当深。即便如此,它还是迅速地称为世界上最受欢迎的语...
2015-12-25
在JavaScript中处理时间之setMinutes()方法的使用
javascript Date.setMinutes()方法按照本地时间的设置分钟为一个指定日期 语法 Date.setMinutes(minutesValue[, secondsValue[, msValue]]) 注:括号内外观和数据...
2017-03-24
jQuery使用append在html元素后同时添加多项内容的方法
本文实例讲述了jQuery使用append在html元素后同时添加多项内容的方法。分享给大家供大家参考。具体分析如下: 下面的代码可以同时在文本段落后添加多项内容 &lt;!DOCTYPE html&gt; &lt;html&gt; &lt...
2017-03-22
自己参考两个仓库撸的通用的vue2.0+elementUI+多页面模板
A modern Vue.js multiple pages cli which uses Vue 2, Webpack3, and Element-UI Features Vue2 Webpack3 ElementUI Eslint(e...
2018-01-12
在AngularJS应用中实现一些动画效果的代码
在Angular当中,CSS和JavaScript之间唯一的区别就是它们的定义。没有什么区别妨碍到被定义的动画被使用。首先,我们需要加载ngAnimate模块到我们应用的root模块当中。 angular.module(&#x27;cour...
2017-03-24
在JavaScript中操作数组之map()方法的使用
JavaScript 数组map()方法创建一个新的数组使用调用此数组中的每个元素上所提供的函数的结果。 语法 array.map(callback[, thisObject]); 下面是参数的详细信息: callback : 从当前的...
2017-03-24
javascript动态创建链接的方法
本文实例讲述了javascript动态创建链接的方法。分享给大家供大家参考。具体分析如下: 动态创建链接示例: &lt;html xmlns=&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;1999&#x2F;...
2017-03-23
在JavaScript应用中使用RequireJS来实现延迟加载
无论简单还是复杂的Web应用,都由一些HTML、JavaScript、CSS文件组成。通常开发者会通过JQuery、Knockout、Underscore等等这样的第三方JavaScript框架来提高开发速度。由于这些JavaScript框...
2017-03-27
回到顶部