自行下载并安装node
pkgtest
目录,进入该目录,建立pkgtest.js
文件,文件内容以下:function pkgtestpkg(param) { console.log('param is: ',param); } exports.pkgtestpkg = pkgtestpkg;
package.json
文件,pkgtest目录下执行npm init
,按提示输入指定的内容便可,例如:package name: (pkgtestpkg) version: (1.0.0) description: first pkg test entry point: (pkgtest.js) test command: git repository: https://github.com/your-github-account/pkgtestpkg.git keywords: pkg test author: npm_user_name //这里要事先在npm官网注册帐号 license: (ISC) ISC
发布包以前必须事先注册一个npm帐号,去官网 https://www.npmjs.com/ 自行注册。git
npm adduser // 输入本身的npm帐号、密码、邮箱
npm login // 输入帐号、密码、邮箱,登陆后方可发包
npm publish
npm unpublish [--force] // 不成功能够强制取消
登陆官网 https://www.npmjs.com/ ,便可看到刚才发布的包,若是网不是很好,可能等一会才能看到。github
进入任意目录下,执行npm init
建立package文件,执行npm i pkgtestpkg
,执行完后,在任意js文件中加载刚才安装的pkgtestpkg
包。例如:npm
let pkgtestpkg = require('pkgtestpkg'); console.log(pkgtestpkg.pkgtestpkg());
git remote add origin git@server-name:path/reponame.git // 关联到远程仓库 git push // 推送上去