Creating npm package from scratch

The Node Package Manager seems to do wonderful job, it is simple to understand and has really well built up. I have created one simple IMDB scraper, which I want to add into repository so I’ll share my tips step by step.

1. I have already created directory imdb-rscraper, put all the package files in the folder, if you have many files create separate folder lib.

2. Create new file called package.json(touch package.json),this is the file where all the metadata is listed. You could basicaly use this template.

{
    "name": "imdb-rscraper",
    "author": "No Public Name here",
    "homepage": "http://veebdev.wordpress.com/",
    "version": "0.0.1",
    "description": "Scraping the data from IMDB with JQuery selectors",
    "main": "imdb-rscraper.js",
    "keywords": [
        "imdb",
        "scraper"
    ],
    "dependencies" : {
        "jsdom": ">= 0.2.12"
    },
    "repository" : {
        "type" : "git",
        "url" : ""
    }
}

3. Now make symlink the package folder run npm link. Creates link /usr/local/lib/node_modules/imdb-rscraper -> /home/risto/node/imdb-rscraper

4. Create the README file for better understanding even for yourself, give brief overview how to use your library, tool.

5. Before publishing you have to create user in repository npm adduser fill the user fields and the publish npm publish. After the last step you should see something like this. Give feedback if I missed something.

npm http PUT https://registry.npmjs.org/imdb-rscraper
npm http 201 https://registry.npmjs.org/imdb-rscraper
npm http GET https://registry.npmjs.org/imdb-rscraper
npm http 200 https://registry.npmjs.org/imdb-rscraper
npm http PUT https://registry.npmjs.org/imdb-rscraper/0.0.1/-tag/latest
npm http 201 https://registry.npmjs.org/imdb-rscraper/0.0.1/-tag/latest
npm http GET https://registry.npmjs.org/imdb-rscraper
npm http 200 https://registry.npmjs.org/imdb-rscraper
npm http PUT https://registry.npmjs.org/imdb-rscraper/-/imdb-rscraper-0.0.1.tgz/-rev/2-18de2cfa3e62cb38e8b13c84deb5db16
npm http 201 https://registry.npmjs.org/imdb-rscraper/-/imdb-rscraper-0.0.1.tgz/-rev/2-18de2cfa3e62cb38e8b13c84deb5db16
+ imdb-rscraper@0.0.1

6. Visit npmjs.org and search for your package with the declared information for each version.

 

About these ads

2 comments


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s