Sunday, August 26, 2012

Create a npm package

npm is package manager for nodejs.

If you want to create and publish npm package you must complete theses steps:

1. Create a profile

Go to npm website and create a profile.

2. Create package.json file

Create a folder for your package and change the current directory to it:
mkdir my_package
cd my_package
Create package.json file:
{ 
  "name" : "my_package",
  "description": "package description goes here",
  "version": "1.0.0",
  "author": "Firstname Lastname <firstname.lastname@mail.com>",
  "keywords": ["my_keyword1", "my_keyword2"], 
  "repository": {
    "type": "git",
    "url": "https://github.com/myuser/my_package.git"
  },
  "main" : "./lib/my_package.js",
  "engines": {
    "node": ">=0.8.8"
  }
}
3. Link with npm

Link your package with npm:
npm link
4. Publish the package

Add a user:
npm adduser
Publish a package:
npm publish
If you want to override published package you can user --force parameter:
npm publish --force

No comments:

Post a Comment