Publishing an NPM Module Part 1

These are my notes based on the phenomenal tutorial by Kent C. Dodds hosted by egghead.io both of which are my go to sources when I want to learn something new. I highly suggest you sign up for the pro subscription.

>Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Part 1 : The Setup

These are my notes based on the phenomenal tutorial by Kent C. Dodds hosted by egghead.io both of which are my go to sources when I want to learn something new. I highly suggest you sign up for the pro subscription. They are focused on a ‘code first’ delivery so you start learning right away. I made these notes to dig a little deeper on some of the topics, but I would not have known where to get started without these two wonderful resources!

I will be using the following icons to denote certain sections.

glyphicons-55-clock  = Time Saving Idea

glyphicons-499-sunglasses = Pro Tip

glyphicons-31-pencil = Note

glyphicons-197-exclamation-sign = Alert

glyphicons-424-git-create = Code Update

glyphicons-28-search  = A Closer Look

Overview

  1. Create the git repo
  2. Create the library
  3. Publish to npm
  4. Create test suites
    1. Karma
    2. Mocha
    3. Chai
  5. Set up continuous Integration
    1. Travis-CI
  6. Add ES6/ES2015
    1. Babel
    2. web pack
  7. Distribute
    1. NPM
    2. GITHUB
    3. UMD

Create the GitHub Repo

First head over to github.com to create your account if you don’t already have one. Next create a new repo. You can skip creating the README.md as we will be making our own in the next few moments. Take note of the url for the repo as we are going to add it in as the origin in the following steps.

$ echo “# Project name” >> README.md
$ git init
$ git add README.md
$ git commit -m "Initial Commit"
$ git remote add origin <git url> //i.e. https://github.com/jmichelin/something.git
$ git push -u origin master

Setting up NPM

Install Node

To verify that you have node installed run:

$ npm -v

Head to https://docs.npmjs.com/ and read about init-author.name, init-author-email, init-author-url, init-license and save-exact. These set up defaults making future projects even easier. The save-exact true makes your project configured with an exact version rather than using npm’s default semver range operator. There are more but these are some of the more common ones that tend not to change between projects. 

glyphicons-55-clock
Run the following commands:

$ npm set init-author-name 'Name' 
$ npm set init-author-email '<your_email>' 
$ npm set init-author -url '<your_website>' 
$ npm set init-license 'MIT'
$ npm set save-exact true //makes sure you use exact versioning

let’s look at npmrc:

$ cat ~/.npmrc

You will see all of the defaults you set above saved there in case you ever want to edit them.

Create npmjs.com account by heading over to npmjs.com and click on sign up.

screen-shot-2016-09-06-at-4-27-30-pm

Then back in your console:

$ npm adduser

enter npmjs account name, password and Email, add user creates an auth token that you should keep private.

$ npm init

Accept default name, version, enter a brief description, entry point is the file that will be looked at when you require(‘module-name’); change the entry point to read src/index.js accept default for test, for github repo, enter some keywords, accept default license, and create package.json.

Next…Creating a Library

glyphicons-499-sunglasses start thinking about what you might want to make and keep it simple.