modular development in node.js

16
Modular Development #NodeNinjas http://www.meetup.com/sydney-node- ninjas

Upload: mehdi-valikhani

Post on 07-Aug-2015

470 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Modular development in Node.js

Modular Development

#NodeNinjashttp://www.meetup.com/sydney-node-

ninjas

Page 2: Modular development in Node.js

Mehdi ValikhaniSoftware Engineer

@mehdivk

https://au.linkedin.com/in/valikhani

http://blog.mehdivk.net

Page 3: Modular development in Node.js

Path To Modular Development

1. In Common Code Across Multiple Projects Example: logger.js, authentication-middleware.coffee

2. Problems With Large Codebases Example: Onboarding new developers, Time to run tests

3. Microservices Architecture Example: Cryptography, Logger

Page 4: Modular development in Node.js

Modular Development Offers:

1. Proper Versioning Example: Different services using different versions of same module

2. Separation of Concerns Example: Easier for new developers to digest codebase.

3. Try Different Technologies Example: Using CoffeeScript, ES6, TypeScript, Babel

Page 5: Modular development in Node.js

Modular Development Offers:

4. Software Documentation Example: How to integrate module, function parameters etc.

5. Enforces TDD Example: Test API via developing unit tests.

Page 6: Modular development in Node.js

NPM Offers:

1. Semantic Versioning (major.minor.patch) Example: Different services using different versions of same module

2. Public & Private Modules Example: npm install @my-business/my-logger

3. Integration With “Git” Example: Host your modules in Github or BitBucket

Page 7: Modular development in Node.js

Git Repos Offer:

1. Versioning using “Tag” Example: npm install my-business/my-logger#v0.2.1

2. Release Backlogs Example: Github offers releases.

Page 8: Modular development in Node.js

A Good Approach ToModular Development

Page 9: Modular development in Node.js

Readme Driven Development

1. Introduced in 2010 By Tom Preston-Werner, Founder of Github

2. Encourages Programmers To Write Readme.md first It’s not just for modules, could be for a cli tool or a project.

3. Offers good concepts for modular development Next slide!

Page 10: Modular development in Node.js

RDD Offers:1. Get feedback without development

Share Public API To Colleagues Via Readme.md usage examples.

2. Better Design Decisions Encourages you to think upfront.

3. Less Refactoring Interaction With Final Product Without Actual Development.

4. Documentation Version backlog, Public API backlog, integration, contribution.

Page 11: Modular development in Node.js

L.I.F.T Principle

1. Locate Your Code Easily

2. Identify Type Of File Instantly

3. Flat Code Structure

4. Try To be DRY (Don’t Repeat Yourself)

Page 12: Modular development in Node.js

Publish A Private Module Via NPM

$: npm login$: npm init //prefix name with @npm-username$: npm version [major,minor,patch] //adds new tags to git as well.$: npm publish

$: npm install @npm-username/module-name

$: git push$: git push --tags

Page 13: Modular development in Node.js

Publish A Private Module Via Git

$: npm init //prefix name with @npm-username$: npm version [major,minor,patch] //adds new tags to git as well.$: git push$: git push --tags

$: npm install git://github.com/ur-acc/repo-name.git#v0.1.0 --save

Page 14: Modular development in Node.js

Symlink modules via “npm link”

$: cd my-project/my-module$: npm link$: cd my-project/my-app$: npm link @mehdivk/my-module

Page 15: Modular development in Node.js

Useful Resources

1. Readme Driven Development http://bit.ly/1dqUYQF

2. L.I.F.T http://bit.ly/1NneG3M

3. Introduction to “Semver” http://bit.ly/1HwhL2r

4. “Semver” calculator http://bit.ly/1NvY0X6

5. NPM Private Modules http://bit.ly/1eR78uD

6. One-line Node.js Modules http://bit.ly/1JyQxbW

Page 16: Modular development in Node.js

Thanks!And It’s Time To Ask Some “EASY” Questions :)