在linux Ubuntu创建npm私有库

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-rootoption 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://<font color="00aadd">[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
原文链接:segmentfault.com

上一篇:关于echarts,数据使用setInterval定时刷新的问题
下一篇:Vue部署资源路径问题

相关推荐

  • 项目中npm依赖问题

    最近开发遇到一个npm依赖导致的问题,报错如下。 sloterror(https://img.javascriptcn.com/804ed4a03d02191762c1f48473ba1711 "sl...

    2 年前
  • 随记-npm

    npm npm是包管理器,方便开发人员分享,复用代码 用于搜索js模块/包的网站 npm服务器可下载或上传安装包或命令行程序 npm仓库存储安装包/安装模块 npm 安装 npm依赖于node,...

    2 个月前
  • 针对前端开发可重用组件并发布到NPM

    翻译:疯狂的技术宅 原文:https://www.smashingmagazine....(https://www.smashingmagazine.com/2018/07/reusablecom...

    1 年前
  • 通过npm引用的vue组件使用详解

    什么是组件:组件是Vue.js最强大的功能之一。组件可以扩展HTML元素,封装可重用的代码。在较高层面上,组件是自定义的元素,Vue.js的编译器为它添加特殊功能。

    3 年前
  • 透过 TDD 模式学习如何实现各种 npm 工具

    前言 在程序員的日常精進之中,閱讀優秀的代碼是必不可少的。透過 TDD 的開發模式,可以模仿那些優秀的代碼,從而提升自己代碼水平。下面介紹如何從零開始搭建 TDD 環境,並構建 isEven 代碼...

    2 年前
  • 边学习变记:npm 常用的几个指令(持续更新。。。)

    在当前文件夹下,地址栏输入cmd 呼出控制台。1.npm init 初始化项目,npm init y 生成默认配置。 2.查看当前使用的镜像地址:npm get registry默认镜像地址:http...

    3 个月前
  • 踩坑札记之 npm 包发布

    重点阐述 npm 包发布前后所踩坑,首先科普如何发布 npm 包。 发布流程 注册账号 开启终端输入: 根据提示输入 username、password、email 即刻注册成功,已注...

    1 年前
  • 贡献你的力量 开发一个Vue组件并发布到npm

    最近在工作中写了一个面向 PC 端的 Vue 滚动组件,关于 PC 端的滚动组件以前也用过一些,但是没有找到特别满意的,所以自己想着把这个组件开源发布出去,希望能够帮到和我有类似需求的人吧! 目标 ...

    2 年前
  • 详解node.js中的npm和webpack配置方法

    概述 Node.js用c语言编写而成的,是一个基于chrome V8引擎的javascript运行环境,让javaScript的运行脱离浏览器服务端,可以使用javaScript语言书写服务器端代码...

    2 年前
  • 记第一次发布npm包经历,smart-import,node-command-line-tool

    故事背景 前情提要:自动 Import 工具,前端打字员的自我救赎(https://segmentfault.com/a/1190000012792016) github: smartimpor...

    2 年前

官方社区

扫码加入 JavaScript 社区