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

被折叠的 条评论
为什么被折叠?



