modular development in node.js
TRANSCRIPT
Modular Development
#NodeNinjashttp://www.meetup.com/sydney-node-
ninjas
Mehdi ValikhaniSoftware Engineer
@mehdivk
https://au.linkedin.com/in/valikhani
http://blog.mehdivk.net
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
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
Modular Development Offers:
4. Software Documentation Example: How to integrate module, function parameters etc.
5. Enforces TDD Example: Test API via developing unit tests.
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
Git Repos Offer:
1. Versioning using “Tag” Example: npm install my-business/my-logger#v0.2.1
2. Release Backlogs Example: Github offers releases.
A Good Approach ToModular Development
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!
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.
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)
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
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
Symlink modules via “npm link”
$: cd my-project/my-module$: npm link$: cd my-project/my-app$: npm link @mehdivk/my-module
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
Thanks!And It’s Time To Ask Some “EASY” Questions :)