为了账号安全,请及时绑定邮箱和手机立即绑定

一分钟发布一个属于自己的npm包

标签:
JavaScript

如何发布一个npm包

1.注册npm账户

登陆 https://www.npmjs.com 用邮箱注册接收验证邮件验证就完事了
(此处有两封邮件:Welcome to npm和Verify your npm email address )

2.选择目标文件夹,命令行cd进去

E:\xxx>cd testE:\xxx\test>

3.执行npm init

输入以下命令,会提示配置包的相关信息,名称版本等等,都是包的基本配置信息

 E:\xxx\test> npm init
 
 详细配置:
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.name: (npm-publish)                       //包名version: (1.0.0)                          //版本号description:                              //描述entry point: (index.js)                   // 入口文件test command:git repository:                          //git仓库地址keywords:                                //关键字author:                                  //作者license: (ISC)                           //开源协议About to write to E:\learn\node\npm-publish\package.json:{  "name": "fashaoge",  "version": "0.0.1",  "description": "the npm pulish test ��, only a test ,please don't install",  "main": "index.js",  "scripts": {    "test": "echo \"Error: no test specified\" && exit 1"
  },  "keywords": [    "test"
  ],  "author": "hu-qi",  "license": "ISC"}


Is this ok? (yes)

4.配置完毕,会生成package.json文件,开始写包的代码

最后一句 :Is this ok? (yes)
创建index.js文件 // 写 module.exports = 123456789;

5.发布包:npm publish 包名

登陆npm

 E:\xxx\test>npm login 
 E:\xxx\test>Username: yourname
 E:\xxx\test>Password: yourpassword
 E:\xxx\test>Email: (this IS public) youremail
E:\xxx\test>npm publish

题外话

一、遇到了一个小小的错误 就是没有通过验证就发包 结果报错了


npm ERR! publish Failed PUT 403npm ERR! Windows_NT 10.0.14393npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\                                                                                            node_modules\\npm\\bin\\npm-cli.js" "publish"npm ERR! node v6.3.0npm ERR! npm  v3.10.3npm ERR! code E403npm ERR! you must verify your email before publishing a new package: https://www                                                                                            .npmjs.com/email-edit :

二、包的删除

npm --force unpublish 包名


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消