From Github.com to npm

TL;DR

Creating a new module

  1. Create a new repo at Github.com.
  2. Clone the repo to your local computer.
  3. Add your new shiny module.
  4. Create a package.json file. Required fields are name and version.
  5. Push all your changes to your master branch at Github.com.
  6. Create a new release at Github.com.
  7. Create an account at npmjs.com.
  8. Publish your new package.
  9. Check that your new shiny package on npmjs.com

Updating an existing module:

  1. Update version inside package.json.
  2. Push all your changes to your master branch at Github.com.
  3. Create a new release at Github.com.
  4. Publish your new package.
  5. Check that your new shiny package on npmjs.com

Details - New module

1. Create a new repo at Github.com

Just follow the instructions on Github.com and you’ll be good.

2. Clone the repo to your local computer

Go to your favorite project directory and type:

$ git clone git@github.com:my-account/my-module.git

3. Add your new shiny module

Now it’s all up to you. Do your magic and add your module. Don’t forget to do unit testing and add a CI integration like Travis.

4. Create a ‘package.json’ file

To create a package.json file just type:

$ npm init

Or if you already have one in your repo make sure name and version are added. All versioning are according to Semver.

5. Push all your changes to Github.com

When your done with all your hard work. Push your changes to Github.com. Just type:

$ git push origin master

6. Create a new release

Now it’s time to make a release on Github.com. It’s good practice to do this before you publish a new npm package. You can do the release on Github.com or you can use curl from command line:

$ curl --data '{"tag_name": "0.2.0","target_commitish": "master","name": "0.2.0","body": "Release of version 0.2.0","draft": false,"prerelease": false}' https://api.github.com/repos/my-account/my-module/releases?access_token=:YOUR_ACCESS_TOKEN

7. Create an account at npmjs.com

Now it’s time to create an npm account. Jump to the “Create an account at npmjs.com“ page and follow the instructions.

When you’re done go back to your repo and type:

$ npm login

# Check login
$ npm config ls

8. Publish your new package

This is very easy. Just type this in your repo folder:

$ npm publish

9. Check that your new shiny package

Now check your new shiny package.

Details - Update module

1. Update version inside ‘package.json’

Remember to bump the version inside package.json. Use Semver to figure out which version you should bump to.

2. Push all your changes to your master branch

Push your changes to the master branch:

$ git push origin master

3. Create a new release at Github.com.

Now it’s time to make a release on Github.com. It’s good practice to do this before you publish a new npm package. You can do the release on Github.com or you can use curl from command line:

$ curl --data '{"tag_name": "0.2.0","target_commitish": "master","name": "0.2.0","body": "Release of version 0.2.0","draft": false,"prerelease": false}' https://api.github.com/repos/my-account/my-module/releases?access_token=:YOUR_ACCESS_TOKEN

4. Publish your new package

This is very easy. Just type this in your repo folder:

$ npm publish

5. Check that your new shiny package

Now check your new shiny package.

That’s all!

If you have any comments please feel free to add them below.