creating-node-modules

1.0.8 • Public • Published

#Creating Node Modules

  1. Create a package.json file

    $ npm init

  2. 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.

  3. 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

  1. 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.

  2. The two required fields are the name and the version.

  3. Create a user with the npm registry.

    $ npm adduser

    ls will 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/~

  4. Finally publish the node module.

    $ npm publish

Readme

Keywords

Package Sidebar

Install

npm i creating-node-modules

Weekly Downloads

1

Version

1.0.8

License

ISC

Last publish

Collaborators

  • icummings