distributing 

modules with 

npm & bower

Modularity

Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality

noun

the use of individually distinct functional units, as in assembling a computer application .

npm

  • national pest management
  • numbers prefer multiplication
  • node pleases me
  • noisy pneumatic mnemonic
  • nonflavored percription medicine

node package manager

Bower

Package manager for the web

  • libraries
  • frameworks
  • utilities
  • assets
  • rainbows

 

let's make a component / module

identifying

modules for

distribution

Traits of a module candidate

  • fits into a problem pattern or category

  • has been implemented in other domain specific ways

  • it's encapsulate-able

identify

module

candidates

isolating

module

candidates

  • encapsulate the candidate functionality in place

  • identify the problem category the functionality solves

  • genericize the implementation

  • eliminate side effects

example

module

development

within an

ongoing project

  • start a new git repo

  • `npm/bower link`

  • unit tests are a must

  • documentation in readme.md

  • package.json `author`, `maintainers`, and `contributors` properties

start a new git repo

$ git init

$ git remote add origin <git-url>

npm link

~/projects/typeoOf $ npm link

...

~/projects/myApp $ npm link typeOf
~/projects/typeoOf $ bower link

...

~/projects/myApp $ bower link typeOf

bower link

unit tests are a must

describe('typeOf()', () => {
    
    it('should return the `type` of a thing', () => {
    
    ...

    });

});

document in the readme.md

#The Awesome `typeOf` module!

give it something and watch it return it's type.

```
typeOf(new Date()) // 'date' No Way!!!!
```

attribution in package.json

{
...
    author: "Gérald Caussé <bishop.causse@ldschurch.org>",
    maintainers: [
        "Portfolio Name <DL-Portfolio@ldschurch.org>",
        "Gary E. Stevenson <bishop.stevenson@ldschurch.org>",
        "Gérald Caussé <bishop.causse@ldschurch.org>",
        "Dean M. Davies <bishop.causse@ldschurch.org>"
        }
    ],
    contributors: [{
        "name": "David A. Bednar",
        "email": "elder.bednar@ldschurch.org"
    }]
...
}

lds-node

module

generator ftw

~/projects/my-module $ yo lds-node:module

git tags

$ git tag -a v1.0.1 -m "added additional use case"

registration

$ npm publish
$ bower register package-name git-endpoint

module

consuming

modules

$ npm install <package-name> --save
$ bower install <package-name> --save

reporting

bugs

  • contact maintainers
  • confirm it's a bug
  • fix it yourself!
  • add yourself as a contributor
  • get used to pull requests
  • you don't rev the version

Sharing Modules of Code with NPM and Bower

By Cory Brown

Sharing Modules of Code with NPM and Bower

  • 1,234