?
Create the node. JS module.
- Create a folder to store module.
- 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.
- Create a portal file Index.js. ( the name can also be set at NPM init )
- 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.
- Create a good Module after the CD to the Module Path, running NPM Pack, will generate a . tgz files,
- Cd to the installation Module the path to execute npm Install <tgz completion Path of the file > , the carriage return has been successfully installed.
- 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.
- 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.
- CD to Module directory, run NPM Publish, will automatically publish to Npmjs above.
- After the publish is complete, you can install it with NPM installed <module name>.
Create and publish the node. JS Module