node.js包的发布

新建一个mypackagemodule的文件

在命令行下切换到给文件下,执行npm init,按要求提示填写 

E:\node\mypackagemodule>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: (mypackagemodule) jinhan

version: (1.0.0) 1.0.0

description: this is my frist mypackagemodule

entry point: (index.js) index.js

test command: none

git repository: none

keywords:

author: jinhan

license: (ISC)

About to write to E:\node\mypackagemodule\package.json:

{

  "name": "jinhan",

  "version": "1.0.0",

  "description": "this is my frist mypackagemodule",

  "main": "index.js",

  "scripts": {

    "test": "none"

  },

  "repository": {

    "type": "git",

    "url": "none"

  },

  "author": "jinhan",

  "license": "ISC"

}

Is this ok? (yes) yes

E:\node\mypackagemodule>

填写成功后在mypackagemodule文件下会出现package.json文件

创建一个index.js作为包的接口,一个包就这样制造好了。

在发布前,我们还需要获得一个账号用于今后维护自己的包,使用 

 npm adduser  根据提示输入用户名、密码、邮箱,等待账号创建完成。完成后可以使用  npm whoami  测验是否已经取得了账号。接下来,在 package.json 所在目录下运行 npm publish ,稍等片刻就可以完成发布了。打开浏览器,访问 http://search.npmjs.org/ 就可以找到自己刚刚发布的包了。现在我们可以在世界的任意一台计算机上使用  npm install mypackagemodule  命令来安装它,如果你的包将来有更新,只需要在 package.json 文件中修改version字段,然后重新使用 npm publish 命令就行了。如果你对已发布的包不满意(比如我们发布的这个毫无意义的包),可以使用  npm unpublish 命令来取消发布。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值