node.js自学笔记(7)-发布包

本文将指导您如何创建、初始化、注册并成功发布一个Node.js包,包括生成package.json、注册用户、发布包及取消发布的过程。

3步搞定包的发布

生成package.json

使用npm init命令进入生成package.json交互状态,然后根据提示输入相关信息。

D:\node.js\0212>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane 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: (0212) testerhome
version: (1.0.0)
description: for testerhome
entry point: (test.js)
test command: test
git repository:
keywords: testerhome doctorq
author: doctorq
license: (ISC) Lsdf2
About to write to D:\node.js\0212\package.json:

{
  "name": "testerhome",
  "version": "1.0.0",
  "description": "for testerhome",
  "main": "test.js",
  "dependencies": {
    "express": "^4.11.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "test"
  },
  "keywords": [
    "testerhome",
    "doctorq"
  ],
  "author": "doctorq",
  "license": "Lsdf2"
}


Is this ok? (yes)

D:\node.js\0212>

这个时候会发现在同级目录下生成了一个package.json文件。里面的内容和上面显示的是一样的,就不再贴出来了。

注册官网用户

通过npm adduser命令注册账户,也是进入交互界面,根据提示输入相应信息就行。注册完成后,可以输入 npm whoami 来验证一些账户是否注册成功。

D:\node.js\0212>npm adduser
Username: doctorq
Password:
Email: (this IS public) 542113578@qq.com

D:\node.js\0212>npm whoami
doctorq

D:\node.js\0212>

上面已经注册成功了。

发布包

通过npm publish命令来发布包

D:\node.js\0212>npm publish
+ testerhome@1.0.0

D:\node.js\0212>

这个时候我们已经成功发布了我们的包,这个时候登录npm官网 进入package搜索页面,搜索testerhome,就会看到我刚才上传的包。

这里写图片描述

如果以后有更新,更新后直接执行npm publish就行,如果对发布的包不满意,可以使用npm unpublish <packagename> [@version] 来取消发布。

D:\node.js\0212>npm unpublish testerhome@1.0.0
- testerhome@1.0.0

D:\node.js\0212>

这个时候再登录npm官网你会看到下面的信息:

这里写图片描述

上面的信息说的就是已经被我unpublish了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值