当前位置:网站首页>How to publish your own NPM package
How to publish your own NPM package
2022-07-25 04:48:00 【Shadow wind Mo】
Preparation
- node Environmental Science , Please go to the official website to download
- npm account number , Please go to this link https://www.npmjs.com/signup register
Create project
perform npm init -y Initialize project 
package.json file :
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"demo": "index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
index.js file :
Be sure to add this line of code : #!/usr/bin/env node It means that node Running code in environment
#!/usr/bin/env node
console.log(' test !!!');
Local testing :
First step : Publish to global under the current release package directory node_modulesnpm link
Go to test and input yourself directly package.json Inside bin Configuration commands , What I have here demo
The result is :
The second step : The global release package is associated under the local test project directory npm link publishname
Disassociate :
It is necessary to test this movie locally . Mainly, canceling the association relationship can reduce the problems such as dependence on development, failure to install and lag .
- Cancel the association between the test project and the global
In the test project executionnpm unlink publishname - Cancel the association between the publishing project and the global
Execute in the release package projectnpm unlink publishname
Publish online :
There are about two steps :
First step : Login account .
perform npm login , No, npm If you have a local account, you need to execute npm adduser Add local npm account number
If you log in here and report an error , Under execution npm config set registry https://registry.npmjs.org , Must be npmjs Source
The second step : Publish to npmjs Official website
perform npm publish
Be careful : If you report here 403 Error of , No permission to submit to this package warehouse , The reason is that the package name has been occupied , Then modify the name of the definition package , Need to be in package.json File modification name Field changes its name , Its name must be preceded by the function domain name @username/packagename This format is named , And username It can only be the current user , perform npm whoami You can view the current user name
边栏推荐
- Tiny-emitter.js: a small event subscription and Publishing Library
- [sht30 temperature and humidity display based on STM32F103]
- Introduction to FileStream class of C #
- 1. If function of Excel
- Data Lake (16): structured streaming writes iceberg in real time
- Deep understanding of pod
- QT download installation tutorial
- Open source summer interview | "after 00" PMC member Bai Zeping
- Actual combat | record an attack and defense drill management
- # 1. Excel的IF函数
猜你喜欢

二、MySQL数据库基础

盐粒和冰粒分不清

Interviewer: explain the core principle of ThreadLocal

The strongest JVM in the whole network is coming!
![[CTF learning] steganography set in CTF -- picture steganography](/img/32/2da78bd5866cfab9ee64dfcb1c1204.png)
[CTF learning] steganography set in CTF -- picture steganography

GDT,LDT,GDTR,LDTR

2、 Mysql database foundation

【浅析STM32之GPIO寄存器(CRL/CRH)配置 】

暗黑王者|ZEGO 低照度图像增强技术解析

ES6 -- Methods and extensions of array objects, traversal of arrays, and extension methods of strings
随机推荐
Millet 100W fast charging, 50W wireless charging technology exposure! Oppo Shen Yiren responded: boring!
Best practice cases of data security in the medical industry (desensitization version)
Thinking from the perspective of Aya
It we media shows off its wealth in a high profile, and is targeted by hacker organizations. It is bound to be imprisoned
GBase 8a 关于No Suitable Driver 问题
Very clear organization
Gbase JDBC connection database exception
[wechat applet] design and interactive implementation of auction product details page (including countdown and real-time update of bids)
GetData table table data join MySQL method
The United States has launched 337 investigations on a number of Chinese companies: Bubugao is full of lying guns!
Data Lake (16): structured streaming writes iceberg in real time
Opencv4.5.x+cuda11.0.x source code compilation and yolov5 acceleration tutorial!
阿亚的角度思考
Libenent and libev
市场是对的
Gradle test and idea test
[wechat applet] picker scroll selector (85/100)
LVGL 8.2 Tabview & Window
LVGL 8.2 Tabview
Completed project series Tutorials - smart campus management system