SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
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
“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...”
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

Más contenido relacionado

La actualidad más candente

DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...DCSF 19 Modernizing Insurance with Docker Enterprise:  The Physicians Mutual ...
DCSF 19 Modernizing Insurance with Docker Enterprise: The Physicians Mutual ...
Docker, Inc.
 

La actualidad más candente (20)

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

Destacado (8)

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

Similar a Let's Write Better Node Modules

API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
Akana
 

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

Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Stackato v5
Stackato v5Stackato v5
Stackato v5
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
 
Stackato v4
Stackato v4Stackato v4
Stackato v4
 
Stackato
StackatoStackato
Stackato
 
Starting from scratch in 2017
Starting from scratch in 2017Starting from scratch in 2017
Starting from scratch in 2017
 
Stackato v2
Stackato v2Stackato v2
Stackato v2
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
Stackato v3
Stackato v3Stackato v3
Stackato v3
 
Why real integration developers ride Camels
Why real integration developers ride CamelsWhy real integration developers ride Camels
Why real integration developers ride Camels
 
Autoframework design
Autoframework designAutoframework design
Autoframework design
 
Creating and Maintaining an Open Source Library
Creating and Maintaining an Open Source LibraryCreating and Maintaining an Open Source Library
Creating and Maintaining an Open Source Library
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
 
Publishing strategies for API documentation
Publishing strategies for API documentationPublishing strategies for API documentation
Publishing strategies for API documentation
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)
 
API Description Languages: Which Is The Right One For Me?
 API Description Languages: Which Is The Right One For Me?  API Description Languages: Which Is The Right One For Me?
API Description Languages: Which Is The Right One For Me?
 
Continuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventContinuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:Invent
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
 

Más de Kevin Whinnery

Best Practices for Cross-Platform Native Applications
Best Practices for Cross-Platform Native ApplicationsBest Practices for Cross-Platform Native Applications
Best Practices for Cross-Platform Native Applications
Kevin Whinnery
 
Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
Kevin Whinnery
 
Write Better JavaScript
Write Better JavaScriptWrite Better JavaScript
Write Better JavaScript
Kevin Whinnery
 
Lessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's AssLessons Learned From Applications That Kicked Titanium's Ass
Lessons Learned From Applications That Kicked Titanium's Ass
Kevin Whinnery
 

Más de Kevin Whinnery (12)

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

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

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
  • 4.
  • 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...”
  • 6.
  • 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