LET’S BUILD BETTER NODE
MODULES
NODE SUMMIT
DECEMBER 2013

Copyright © twilio Inc. 2013
HI. I’M KEVIN.
developer evangelist @ twilio
What is twilio?
twilio makes it easy for developers to
integrate voice calling and messaging
into web and native mobile applications
Let's Write Better Node Modules
“The goal is to have lots of user-created
modules, that are all single-purpose and
focused...so you can iterate get the best
experience possible...”
Let's Write Better Node Modules
https://scalenpm.org
49,000
PACKAGES
PyPI: ~37K | RubyGems: ~67K | NuGet: ~18K
6,000,000+
DOWNLOADS PER DAY
Downloads in millions for October

request

optimist

connect

lodash

0

0.35

0.7

1.05

1.4

USERLAND CARRIES A HEAVY LOAD
IF USERLAND SUCKS,
NODE SUCKS.
HOW WE CAN HELP
• Provide accurate documentation optimized for how people read on
the internet (scanning and searching)
• Design idiomatic APIs that optimize for the job your module will be
hired to do
• Implement test automation and basic release management
DOCUMENTATION
DOCUMENT ALL THE THINGS
• Very few userland modules have effective docs - common open
source problem
• Every module has different documentation needs
• Great resource: Kevin Burke’s talk on this subject
• Two most important components for node modules:
• README (quick start)
• API Docs
AN EFFECTIVE README
• Focus on the job your module will be “hired” to do
• Get user to success ASAP by staying focused:
• What job does your module do?
• How do you install/configure it?
• ~3 examples of how to do the thing your module would be
hired to do
• Link to API docs and deeper info sources
CASE STUDIES
• Mongoose: https://npmjs.org/package/mongoose
• jsdom: https://npmjs.org/package/jsdom
• browserify: https://npmjs.org/package/browserify
• request: https://npmjs.org/package/request
• node-uuid: https://npmjs.org/package/node-uuid
EFFECTIVE API DOCS
• Describe the complete surface area of the API
• Provide context for how the API is meant to be used
• Make content readable and scannable
• Provide complete and correct examples, but do not rely on them as
API documentation
• “Read the tests” is a cop out (see above)
DESCRIBING A NODE.JS API
• Document all properties and functions from module.exports (harder
than it sounds)
• Document all function signatures
• Function docs should ideally have:
• Return value/type
• Argument types
• Example usage
PROVIDING CONTEXT
• Show how your code is intended to be used
• Demonstrate how it interconnects with other modules/platform
features
• Describe high-level use cases and concepts unique to your module
MAKE CONTENT READABLE
• Users don’t read docs word for word - they scan in an F shape,
looking for relevant bits
• Include a table of contents for longer content (https://github.com/
thlorenz/doctoc)
• Make the first 3-5 words of every line contain the most information
possible
• Use headers/images/code to break up scary blocks of text
• Limit text on a page to columns of ~80 characters
PROVIDE EXAMPLES
• Reinforce written docs with sample code that shows actual usage
• Ideally, examples should be copy/cut/paste ready - include any
necessary setup/teardown, including the “require”
• Accuracy is key - broken examples are super frustrating
CASE STUDIES
• Mongoose: http://mongoosejs.com/index.html
• express: http://expressjs.com/api.html
• browserify: https://github.com/substack/node-browserify
• request: https://github.com/mikeal/request
• node-uuid: https://npmjs.org/package/node-uuid
API DESIGN
NODE.JS MODULE API DESIGN
• Check out: https://www.youtube.com/watch?v=aAb7hSCtvGw
• Design for async usage
• Use streams for I/O
• Be mindful of the job your module has been hired to do
DESIGNING FOR ASYNC
• Do not release Zalgo
• Node core modules use a specific type of signature for async APIs
that require callbacks
• Function takes whatever arguments, and a callback
• Callback is called with any error received as the first argument,
formatted data is the second.
• Sometimes there’s a third arg with a “raw” value in userland
DESIGN FOR STREAMS
• If you do any sort of I/O, you’d do well to make your interface speak
streams
• Your API will interoperate well with the rest of the node ecosystem if
you work with readable and writable streams
• “When you grok streams, you grok node” - Isaac paraphrase
BE MINDFUL OF YOUR PURPOSE
• Your module might do a few different things, but it probably has a
few 80% use cases
• Your API should be designed to do those jobs as quickly and
efficiently as possible, with sensible default behavior
CASE STUDIES
• browserify: https://github.com/substack/node-browserify
• request: https://github.com/mikeal/request
• twilio: http://twilio.github.io/twilio-node
TESTING AND RELEASES
MANAGING YOUR PROJECT
• Ensure quality with testing and test automation (which can be super
easy)
• Ensure sanity with your module releases by using semantic
versioning
MANAGING YOUR PROJECT
• Promote quality with testing and test automation (which can be
super easy)
• Ensure sanity with your module releases by using semantic
versioning
TESTING/AUTOMATION
• Lots of great test frameworks, pick your favorite or just use assert
• Do support “npm test”
• Travis CI is your friend, and super easy to set up
RELEASE MANAGEMENT
• If you follow semantic versioning, you’re probably doing fine
• If an API breaks from 1.4 to 1.5, that’s a Very Bad Thing
• Use git tags that match your npm versions
• Doing the above makes release notes/change log very easy
CASE STUDIES

• twilio: http://twilio.github.io/twilio-node
WRAPPING UP
• You probably don’t get paid to write and share your module - thank
you for contributing!
• node.js relies on userland modules more than any other major
server-side platform
• If we care about the node ecosystem and community, we all have to
step up with the quality of our contributions
THANK YOU!
@kevinwhinnery
kw@twilio.com
http://github.com/kwhinnery
http://slideshare.net/kwhinnery

More Related Content

PDF
Building Composable Serverless Apps with IOpipe
PDF
Making Sense of Serverless Computing
PDF
Web app development with Flask
PDF
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
PDF
PDF
An Introduction to ReactNative
PDF
Async Web and Python
PDF
Contributing to open source
Building Composable Serverless Apps with IOpipe
Making Sense of Serverless Computing
Web app development with Flask
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
An Introduction to ReactNative
Async Web and Python
Contributing to open source

What's hot (20)

PPTX
NativeScript Developer Day Keynote - Todd Anglin & Burke Holland
PPT
Introduction to Django-Celery and Supervisor
PPTX
AngularJS Anatomy & Directives
PDF
Managing Jenkins with Python
PPTX
Managing SharePoint Anywhere with Windows PowerShell
PPTX
2014 SpiceWorld London Breakout
PDF
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
PPTX
Untangling - fall2017 - week 9
PPTX
Build PWA with Ionic Toolkit
PPTX
Parallel Testing with Python with Selenium and Sauce Labs
PPTX
Serverless meetup - OpenWhisk overview and architecture
PDF
Crafting interactive troubleshooting guides and team documentation for your K...
PPTX
Amazon Web Services for the .NET Developer
PDF
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
PPTX
Azure CLI 2.0 Tips and Tricks
PPTX
Untangling - fall2017 - week 10
PPTX
Serverless Summit India 2017: Fission
PPTX
Introduction to PowerShell at Chicago Code Camp 2014
PPTX
Rik Hepworth - ARM Yourself for Effective Azure Provisioning
PPTX
ASP.NET Core deployment options
NativeScript Developer Day Keynote - Todd Anglin & Burke Holland
Introduction to Django-Celery and Supervisor
AngularJS Anatomy & Directives
Managing Jenkins with Python
Managing SharePoint Anywhere with Windows PowerShell
2014 SpiceWorld London Breakout
.NET Day Switzerland 2019 - DOCKER + AZURE DEVOPS + KUBERNETES = ♥
Untangling - fall2017 - week 9
Build PWA with Ionic Toolkit
Parallel Testing with Python with Selenium and Sauce Labs
Serverless meetup - OpenWhisk overview and architecture
Crafting interactive troubleshooting guides and team documentation for your K...
Amazon Web Services for the .NET Developer
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
Azure CLI 2.0 Tips and Tricks
Untangling - fall2017 - week 10
Serverless Summit India 2017: Fission
Introduction to PowerShell at Chicago Code Camp 2014
Rik Hepworth - ARM Yourself for Effective Azure Provisioning
ASP.NET Core deployment options
Ad

Viewers also liked (8)

PPT
Marketing de Luxo Digital
PPTX
The Right Metrics to Optimize: Three metrics every marketer should focus on
PDF
Taking UX to the Real World
PDF
Pharma Digital IQ
PDF
Digital Strategy Report Card: Is your EDU passing or failing?
PDF
JavaScript as a First-Class Citizen on iOS 7
PPT
Whats New in Titanium 0.7
Marketing de Luxo Digital
The Right Metrics to Optimize: Three metrics every marketer should focus on
Taking UX to the Real World
Pharma Digital IQ
Digital Strategy Report Card: Is your EDU passing or failing?
JavaScript as a First-Class Citizen on iOS 7
Whats New in Titanium 0.7
Ad

Similar to Let's Write Better Node Modules (20)

PDF
Best practices for creating modular Web applications
PPTX
Nodejs web service for starters
PDF
Learning Nodejs For Net Developers Harry Cummings
PDF
Day In A Life Of A Node.js Developer
PDF
Day in a life of a node.js developer
PPTX
NodeJs
PPTX
Intro To Node.js
PPTX
Intro to Node.js (v1)
PDF
Introduction to nodejs
PPTX
A complete guide to Node.js
PDF
NodeJS
PDF
Modern UI Development With Node.js
PPT
Node js
PDF
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
PDF
540slidesofnodejsbackendhopeitworkforu.pdf
PDF
The Happy Path: Migration Strategies for Node.js
PDF
Build Web Apps using Node.js
PPTX
The Future of Node - @rvagg - NodeConf Christchurch 2015
PPTX
Node js Powerpoint Presentation by PDEU Gandhinagar
PPTX
Node.js Getting Started &amd Best Practices
Best practices for creating modular Web applications
Nodejs web service for starters
Learning Nodejs For Net Developers Harry Cummings
Day In A Life Of A Node.js Developer
Day in a life of a node.js developer
NodeJs
Intro To Node.js
Intro to Node.js (v1)
Introduction to nodejs
A complete guide to Node.js
NodeJS
Modern UI Development With Node.js
Node js
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
540slidesofnodejsbackendhopeitworkforu.pdf
The Happy Path: Migration Strategies for Node.js
Build Web Apps using Node.js
The Future of Node - @rvagg - NodeConf Christchurch 2015
Node js Powerpoint Presentation by PDEU Gandhinagar
Node.js Getting Started &amd Best Practices

More from Kevin Whinnery (12)

PDF
Get Pumped for the HTML 5 Gamepad API
PDF
Designing Modules for the Browser and Node with Browserify
PDF
Second Screen Apps with the Google Cast SDK
PPTX
Best Practices for Cross-Platform Native Applications
PPTX
Write Better JavaScript
PPTX
Write Better JavaScript
PPTX
Lessons Learned From Applications That Kicked Titanium's Ass
PPT
Titanium Overview (Mobile March 2011)
PPT
What's New in Titanium 1.5
PPT
OSCON Titanium Tutorial
ZIP
Titanium @ Minnebar
PPT
Getting Started with Titanium
Get Pumped for the HTML 5 Gamepad API
Designing Modules for the Browser and Node with Browserify
Second Screen Apps with the Google Cast SDK
Best Practices for Cross-Platform Native Applications
Write Better JavaScript
Write Better JavaScript
Lessons Learned From Applications That Kicked Titanium's Ass
Titanium Overview (Mobile March 2011)
What's New in Titanium 1.5
OSCON Titanium Tutorial
Titanium @ Minnebar
Getting Started with Titanium

Recently uploaded (20)

PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
UiPath Agentic Automation session 1: RPA to Agents
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PPT
What is a Computer? Input Devices /output devices
PDF
STKI Israel Market Study 2025 version august
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
Developing a website for English-speaking practice to English as a foreign la...
Convolutional neural network based encoder-decoder for efficient real-time ob...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
1 - Historical Antecedents, Social Consideration.pdf
UiPath Agentic Automation session 1: RPA to Agents
Chapter 5: Probability Theory and Statistics
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Zenith AI: Advanced Artificial Intelligence
Custom Battery Pack Design Considerations for Performance and Safety
What is a Computer? Input Devices /output devices
STKI Israel Market Study 2025 version august
Taming the Chaos: How to Turn Unstructured Data into Decisions
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
The influence of sentiment analysis in enhancing early warning system model f...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Credit Without Borders: AI and Financial Inclusion in Bangladesh
A comparative study of natural language inference in Swahili using monolingua...
Final SEM Unit 1 for mit wpu at pune .pptx
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
A proposed approach for plagiarism detection in Myanmar Unicode text

Let's Write Better Node Modules

  • 1. LET’S BUILD BETTER NODE MODULES NODE SUMMIT DECEMBER 2013 Copyright © twilio Inc. 2013
  • 2. HI. I’M KEVIN. developer evangelist @ twilio
  • 3. What is twilio? twilio makes it easy for developers to integrate voice calling and messaging into web and native mobile applications
  • 5. “The goal is to have lots of user-created modules, that are all single-purpose and focused...so you can iterate get the best experience possible...”
  • 8. 49,000 PACKAGES PyPI: ~37K | RubyGems: ~67K | NuGet: ~18K
  • 10. Downloads in millions for October request optimist connect lodash 0 0.35 0.7 1.05 1.4 USERLAND CARRIES A HEAVY LOAD
  • 12. HOW WE CAN HELP • Provide accurate documentation optimized for how people read on the internet (scanning and searching) • Design idiomatic APIs that optimize for the job your module will be hired to do • Implement test automation and basic release management
  • 14. DOCUMENT ALL THE THINGS • Very few userland modules have effective docs - common open source problem • Every module has different documentation needs • Great resource: Kevin Burke’s talk on this subject • Two most important components for node modules: • README (quick start) • API Docs
  • 15. AN EFFECTIVE README • Focus on the job your module will be “hired” to do • Get user to success ASAP by staying focused: • What job does your module do? • How do you install/configure it? • ~3 examples of how to do the thing your module would be hired to do • Link to API docs and deeper info sources
  • 16. CASE STUDIES • Mongoose: https://npmjs.org/package/mongoose • jsdom: https://npmjs.org/package/jsdom • browserify: https://npmjs.org/package/browserify • request: https://npmjs.org/package/request • node-uuid: https://npmjs.org/package/node-uuid
  • 17. EFFECTIVE API DOCS • Describe the complete surface area of the API • Provide context for how the API is meant to be used • Make content readable and scannable • Provide complete and correct examples, but do not rely on them as API documentation • “Read the tests” is a cop out (see above)
  • 18. DESCRIBING A NODE.JS API • Document all properties and functions from module.exports (harder than it sounds) • Document all function signatures • Function docs should ideally have: • Return value/type • Argument types • Example usage
  • 19. PROVIDING CONTEXT • Show how your code is intended to be used • Demonstrate how it interconnects with other modules/platform features • Describe high-level use cases and concepts unique to your module
  • 20. MAKE CONTENT READABLE • Users don’t read docs word for word - they scan in an F shape, looking for relevant bits • Include a table of contents for longer content (https://github.com/ thlorenz/doctoc) • Make the first 3-5 words of every line contain the most information possible • Use headers/images/code to break up scary blocks of text • Limit text on a page to columns of ~80 characters
  • 21. PROVIDE EXAMPLES • Reinforce written docs with sample code that shows actual usage • Ideally, examples should be copy/cut/paste ready - include any necessary setup/teardown, including the “require” • Accuracy is key - broken examples are super frustrating
  • 22. CASE STUDIES • Mongoose: http://mongoosejs.com/index.html • express: http://expressjs.com/api.html • browserify: https://github.com/substack/node-browserify • request: https://github.com/mikeal/request • node-uuid: https://npmjs.org/package/node-uuid
  • 24. NODE.JS MODULE API DESIGN • Check out: https://www.youtube.com/watch?v=aAb7hSCtvGw • Design for async usage • Use streams for I/O • Be mindful of the job your module has been hired to do
  • 25. DESIGNING FOR ASYNC • Do not release Zalgo • Node core modules use a specific type of signature for async APIs that require callbacks • Function takes whatever arguments, and a callback • Callback is called with any error received as the first argument, formatted data is the second. • Sometimes there’s a third arg with a “raw” value in userland
  • 26. DESIGN FOR STREAMS • If you do any sort of I/O, you’d do well to make your interface speak streams • Your API will interoperate well with the rest of the node ecosystem if you work with readable and writable streams • “When you grok streams, you grok node” - Isaac paraphrase
  • 27. BE MINDFUL OF YOUR PURPOSE • Your module might do a few different things, but it probably has a few 80% use cases • Your API should be designed to do those jobs as quickly and efficiently as possible, with sensible default behavior
  • 28. CASE STUDIES • browserify: https://github.com/substack/node-browserify • request: https://github.com/mikeal/request • twilio: http://twilio.github.io/twilio-node
  • 30. MANAGING YOUR PROJECT • Ensure quality with testing and test automation (which can be super easy) • Ensure sanity with your module releases by using semantic versioning
  • 31. MANAGING YOUR PROJECT • Promote quality with testing and test automation (which can be super easy) • Ensure sanity with your module releases by using semantic versioning
  • 32. TESTING/AUTOMATION • Lots of great test frameworks, pick your favorite or just use assert • Do support “npm test” • Travis CI is your friend, and super easy to set up
  • 33. RELEASE MANAGEMENT • If you follow semantic versioning, you’re probably doing fine • If an API breaks from 1.4 to 1.5, that’s a Very Bad Thing • Use git tags that match your npm versions • Doing the above makes release notes/change log very easy
  • 34. CASE STUDIES • twilio: http://twilio.github.io/twilio-node
  • 35. WRAPPING UP • You probably don’t get paid to write and share your module - thank you for contributing! • node.js relies on userland modules more than any other major server-side platform • If we care about the node ecosystem and community, we all have to step up with the quality of our contributions