Create and publish the node. JS Module

Source: Internet
Author: User

?

Create the node. JS module.
  1. Create a folder to store module.
  2. Cdto the newly created folder, runNPM Init,will prompt for input Packagethe information.

    You can follow this video to enter. the Test command can be empty. The package name cannot have capital letters, and if you want to publish it to the public, use a name that is not the same as the existing module.

    Input after input Yes, or y, will generate a Package.json file.

  3. Create a portal file Index.js. ( the name can also be set at NPM init )
  4. in the Index.js enter the following content in the ( This is a test, or it can be something else )

Exports.printmsg = function () {

Console.log ("This was a message from the demo package");

}

one of the simplest ? Module it was created successfully.

Install the module locally.
  1. Create a good Module after the CD to the Module Path, running NPM Pack, will generate a . tgz files,
  2. Cd to the installation Module the path to execute npm Install <tgz completion Path of the file > , the carriage return has been successfully installed.
  3. create a file in the current directory test.js ( can also be a different name ) , enter the following content.

var testmodule = require (' NodeJsModule1 ');

Testmodule.printmsg ();

?

Release module.
    1. Registered users

      NPM Add user will be prompted to enter a username, password and mailbox, and the mailbox will be exposed.

      After creating the user can go to http://npmjs.com/~, to log in to see if the success.

    2. CD to Module directory, run NPM Publish, will automatically publish to Npmjs above.
    3. After the publish is complete, you can install it with NPM installed <module name>.

Create and publish the node. JS Module

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.