creating-node-modules
v1.0.8
Published
In this tutorial we will learn how to create our own node module.
Readme
#Creating Node Modules
Create a package.json file
$ npm init
Automated response ask you questions to build the package.json file. ex: First it asks for a name, then version number, decription etc. Some fields have a default, others can be left blank.
Next create an index.js file. In that file, add a function as a property of the exports object. This will make the function available to other code.
// My module exports.printMsg = function() { console.log("This message is from the npm-demo-pkg"); }
#Publishing Node Modules
You can publish packages that are not node modules. In fact, any files that are buddled together with a package.json file can be handled as a module.
The two required fields are the name and the version.
Create a user with the npm registry.
$ npm adduser
lswill can show you the information that is stored locally for your user. You can also test that your new user has been created by going to: npmjs.org/~Finally publish the node module.
$ npm publish
