How to Use npm to package and release the nodejs package and npm to package and release nodejs

Source: Internet
Author: User

How to Use npm to package and release the nodejs package and npm to package and release nodejs

Author: zhanhailiang Date:

No matter how internal projects are developed based on any language, we often encapsulate some extremely universal functional modules inside. If we think that this general-purpose module is useful to other teams, it can be fully open-source.Npm is the best tool for releasing nodejs packages.

1. register an account at npmjs.org: (saved)

  • Https://www.npmjs.org/signup

2. Use npm adduser to register a new account or log on to the old account:

[root@~/wade/nodejs/pv-tj]# npm adduserUsername: billfellerPassword: Email: (this IS public) 531958936@qq.com

3. npm init is used locally to develop the corresponding modules. Note that the interface exposed externally is standardized in the main file. for usage of npm init, see previous articles, I will not describe it in detail here:

  • Fast real-time online user count statistics based on express + redis

4. After the module development is completed, you can package and release the corresponding package through npm publish:

[root@~/wade/nodejs/uv-tj]# npm publish+ uv-tj@1.0.0

For npm publish usage, see:

  • Npm-publish

5. Now you can check the uv-tj package on npmjs.org:


6. Next we can use the uv-tj package like other packages:

[root@~/wade/nodejs]# git clone git@github.com:billfeller/uv-tj-demo.gitInitialized empty Git repository in /root/wade/nodejs/uv-tj-demo/.git/remote: Counting objects: 5, done.remote: Compressing objects: 100% (4/4), done.remote: Total 5 (delta 0), reused 0 (delta 0)Receiving objects: 100% (5/5), done.[root@~/wade/nodejs]# cd uv-tj-demo/[root@~/wade/nodejs/uv-tj-demo]# npm initThis 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 fieldsand exactly what they do. Use `npm install <pkg> --save` afterwards to install a package andsave it as a dependency in the package.json file. Press ^C at any time to quit.name: (uv-tj-demo) version: (1.0.0) description: entry point: (index.js) test command: git repository: (https://github.com/billfeller/uv-tj-demo.git) keywords: uv tj module demoauthor: billfellerlicense: (ISC) MITAbout to write to /root/wade/nodejs/uv-tj-demo/package.json: {  "name": "uv-tj-demo",  "version": "1.0.0",  "description": "uv-tj-demo ==========",  "main": "index.js",  "scripts": {    "test": "echo \"Error: no test specified\" && exit 1"  },  "repository": {    "type": "git",    "url": "https://github.com/billfeller/uv-tj-demo.git"  },  "keywords": [    "uv",    "tj",    "module",    "demo"  ],  "author": "billfeller",  "license": "MIT",  "bugs": {    "url": "https://github.com/billfeller/uv-tj-demo/issues"  },  "homepage": "https://github.com/billfeller/uv-tj-demo"}  Is this ok? (yes) yes[root@~/wade/nodejs/uv-tj-demo]# vim package.json [root@~/wade/nodejs/uv-tj-demo]# npm i uv-tj --saveuv-tj@1.0.0 node_modules/uv-tj├── redis@0.12.1└── express@4.10.2 (utils-merge@1.0.0, merge-descriptors@0.0.2, fresh@0.2.4, cookie@0.1.2, escape-html@1.0.1, range-parser@1.0.2, cookie-signature@1.0.5, finalhandler@0.3.2, vary@1.0.0, media-typer@0.3.0, methods@1.1.0, parseurl@1.3.0, serve-static@1.7.1, content-disposition@0.5.0, path-to-regexp@0.1.3, depd@1.0.0, qs@2.3.2, etag@1.5.0, on-finished@2.1.1, debug@2.1.0, proxy-addr@1.0.3, send@0.10.1, accepts@1.1.3, type-is@1.5.3)[root@~/wade/nodejs/uv-tj-demo]# vim index.js[root@~/wade/nodejs/uv-tj-demo]# npm start > uv-tj-demo@1.0.0 start /root/wade/nodejs/uv-tj-demo> node index.js

Access through a browser:


Complete code can be found:

  • Https://github.com/billfeller/uv-tj-demo

7. You can also run git clone https://github.com/billfeller/uv tj-demoto to test NPM install directly:

[root@~/wade/test]# git clone https://github.com/billfeller/uv-tj-demoInitialized empty Git repository in /root/wade/test/uv-tj-demo/.git/remote: Counting objects: 9, done.remote: Compressing objects: 100% (7/7), done.remote: Total 9 (delta 1), reused 4 (delta 0)Unpacking objects: 100% (9/9), done.[root@~/wade/test]# cd uv-tj-demo/[root@~/wade/test/uv-tj-demo]# lsindex.js  LICENSE  package.json  README.md[root@~/wade/test/uv-tj-demo]# npm installuv-tj@1.0.0 node_modules/uv-tj├── redis@0.12.1└── express@4.10.2 (merge-descriptors@0.0.2, utils-merge@1.0.0, fresh@0.2.4, cookie@0.1.2, escape-html@1.0.1, range-parser@1.0.2, cookie-signature@1.0.5, finalhandler@0.3.2, vary@1.0.0, media-typer@0.3.0, methods@1.1.0, parseurl@1.3.0, serve-static@1.7.1, content-disposition@0.5.0, path-to-regexp@0.1.3, depd@1.0.0, qs@2.3.2, on-finished@2.1.1, etag@1.5.0, debug@2.1.0, type-is@1.5.3, proxy-addr@1.0.3, send@0.10.1, accepts@1.1.3)[root@~/wade/test/uv-tj-demo]# npm start > uv-tj-demo@1.0.0 start /root/wade/test/uv-tj-demo> node index.js

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.