You can write brilliant code that nobody can use because the documentation is impenetrable. Or you can write average code with excellent docs that becomes everyone’s go-to solution.
Documentation is a multiplier. These principles help you write docs that work.
Know Your Audience# Different readers need different docs:
Tutorials (learning-oriented): “Follow these steps to build X”
For newcomers Hand-holding is okay Complete, working examples Progressive complexity How-to Guides (task-oriented): “How to do X”
For users with specific goals Assume basic familiarity Direct and practical Problem → solution format Reference (information-oriented): “X works like this”
For experienced users Complete and accurate Consistent structure Searchable Explanation (understanding-oriented): “Why X works this way”
For curious users Background and context Design decisions Trade-offs discussed Start with the Problem# Don’t start with your solution. Start with what the reader is trying to do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
❌ Bad:
# MyLib API
MyLib uses a functional composition pattern with monadic
error handling to provide type-safe data transformations.
✅ Good:
# MyLib: Transform Data Without the Boilerplate
Transform arrays, objects, and async data with a simple,
chainable API. No more nested loops or try-catch blocks.
```javascript
// Before: 15 lines of error-prone code
// After:
const result = transform(data)
.filter(isValid)
.map(normalize)
.get();
# E ` ❌ T ✅ T ` c } a a # v ` h h ` o ) w w e ` B e G e ` n c } ; a a S r m a o j s a F i S i h y a d ` o ` a t c t m i t e t o r : c d c v h t a r c w c k a : a a c e l x s c o c , o d c c s l : : S t l n l n o h h c i i i d i D c w e e r e { 3 z c e e o e n ` ` i n 6 e a n c n n p p t 0 : l t a t ' t o o t 0 l . l . t p p = , ' g l g n t t 1 h e e J e i i n 0 i t r t u e o o e 0 t ( e ( s d n n w m s ' t ' t s b / u / e e A ' t u r u T a n n P , h s n s e a a I e e s e l c b b ( r r l o l l { A s c s d e e P ' a ' e s s C M I ) c ) a a ; h ; e r r c x e x e e h i d a s s e m m p p u r p o o f m 2 e 2 l n n o 0 s m e s s r c 0 p s : e e a m o 1 c s n c c h s a a h e e c c o h h u s i i r i n n z g g e : w i t h c o n f i g u r a b l e T T L . # E ` ❌ ` c # x ` ` o a ` B ` n C m m a j I s o p a d a n t p l r : v i y e k a t c - s d s i l P o c a i a s w r l e s h n i i n t o p z t e u t e l = R d t e h n a w e e d o w y r c k l M i y w e C h n l e t i n e n c t o ( p Y i O e U d R _ d A i P r I e _ c K t E l Y y ) : ; ✅ Good:
1
2
3
4
5
6
7
8
9
10
11
import { MyClient } from 'mylib' ;
const client = new MyClient ({
apiKey : process . env . MY_API_KEY ,
// Optional: customize timeout
timeout : 5000 ,
});
// Verify connection
const status = await client . ping ();
console . log ( status ); // { ok: true, latency: 42 }
I # D ` # G ` n n # o ` # e ` p c n ` t ` m l P ' m Q b u r t a u r a i d o r i u s n e g k c n h s r v d k n t i e e o i a m s r w S n l p s w n t g l o i h a r v e r i m t e l t n y s m l . D . 3 i i 0 b U s S s c t s e l a e o r c r s t o e u n a r s d l e i s i m : s p t l i e c , v a a d l d u e c s o . m p S l h e o x w i t e y x : p e c t e d o u t p u t .
1
2
import { process } from 'mylib' ;
const result = process ( data );
Configuration# Customize behavior with options:
1
2
3
4
const result = process ( data , {
strict : true ,
format : 'json' ,
});
Advanced Usage# For complex scenarios, use the streaming API…
# D ` # # T ` t } } # o ` # # h ` r c ` # r ` y a c i } E u m E o j w a f r m a r A w a { a t c r e r r u n v i c ( o o n k o t a t h e n r t d r h w s r R s o s e h c c ( r e o D w w n e r l e o f l o h n t n i i r r r e c a i p e r e . u t c t t n o i s e m a h t r n h r e g t e . ) s r n o i c t y o t e o A o { a o r a s n P n n u ( t E I n c r ' i w r e e I o r r k c o A n n o o e t f P v n r y ( I a g ) A l , i ; u k i s t e d n h y o i e A t n n a P v t t I j a i u l c d k s i a a e t d t s y i h : w o o b ' h r n o , a E a t e r r e x r d r g p o . r o i r e o e r ) x r s e a . d { m m r . p e i l s g e s h . a t c g : o e m ) ; Common causes:
API key copied incorrectly (check for trailing spaces) Key expired (keys expire after 90 days) Wrong environment (staging key used in production) # D ` # ` n # e ` # ` p v ` ` m S e m I b t l a n a i r o r s s n u p k t h s c e d a t t r o l a u s w l l r n a l e s t c i m f a o y o n n l r , i b S t c h a e n y n i d n o g n ' t r e a d l i n e a r l y :
Basic Usage# 1
2
import { MyLib } from 'mylib' ;
const lib = new MyLib ();
API Reference# process(data, options)# Transform input data according to rules.
Parameters:
Name Type Required Description data Object Yes Input data to process options.strict boolean No Enable strict validation
Returns: ProcessedData
Throws: ValidationError if data is invalid
U # O ` d } s # u ` e ) e t ` s i } ; K d j I c t ) h e a a n r ( c e ; e e t v i ' o x a p e a y b Q n p d d s o e u C s e e E c u ( i o t c r x d r r ' c p t s a o i D k y r ( , m c p t o - e r p s t e c S p s e t l s u t a u s a e a t m a s l u b s r e r t t l l e s n t e t e U u t = ) s p w i a e f . , d o t t x r p t a r e i a o r o c t s o m m o B o e e n p c e d d l d e D e t e e o s e h x c s f b a a w s ( i l n m o d n o p r a e c n l k t d k o e s a ( s s ' ) ) , d ' , ; ; o , a c a n s s d : y n b = c u > l l { e t = > p o { i n t s . W a l l s o f t e x t g e t s k i p p e d . Test your examples in CI. Broken examples break trust.
Write for Search# People find docs through search. Include terms they’ll search for:
1
2
3
4
# Handling Timeouts
When requests take too long (timeout errors, ETIMEDOUT,
request timeout), use the `timeout` option:
Think: “What would I search for if I had this problem?”
Version Your Docs# Docs for v2 shouldn’t confuse v1 users:
d ├ │ ├ │ └ o ─ ─ ─ c ─ ─ ─ s / v └ v └ l 1 ─ 2 ─ a / ─ / ─ t e g g s e e t t t t t i i n n g g v - - 2 s s t t a a r r t t e e d d . . m m d d Or use version selectors in your doc site.
A good README follows this pattern:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Project Name
One-sentence description of what it does.
## Features
- Feature 1
- Feature 2
- Feature 3
## Installation
```bash
npm install project-name
Quick Start# 1
// Minimal working example
Documentation# Link to full docs.
Contributing# How to contribute.
License# MIT
# # D W # # o r c i W * * * * * T * * * * * u t r A S P S A o M D J V M m e i c e r h v o a o S a e e t t c e o o l r c D l r n t i i o s r i s k u o e m t h n v n e t d d s c a a e g e d n o a * i t t s j w u T : d i d S p e a n r y * o o t o e t n r * u p P * n c y i r e t g * s e r : s l c s n e o : / D o i e e o s n n V o s D s y * n e c * U i c e i o * * * e * n t * a a u : * * s : i e * l g : : * v P : i r p w " * O e r n a r i T " " : r r e A t m o s h Y T s s P i s d h e o h B d a s I n u u i r e l * g a c e f s e f , * d s t x u c a i : o . i n a c k n v c c s c n r e e F s o I t t e u r o d t e i c a p i s r f e d o o t t i r h n n e c o d o a w f s o w n o m s h r i m h - c e e g a p e c u c u n t u l n o m o s u r f e n e d e y r e i x y t n e r o n . l o r t s u s . e e u o a . " x l t ( w X " p m l i d e " n l u e o e r n o a s d n v e n o t n t e o t a s l l t " t u i o e " T i s t p a " U h o e e e r X s i n s r n e s s i s i i r t ) n s s w , g i . r c l i e a l t F t n u u c s t r c r o u n o e l r e n a v e d f t e i e s d b g e y u a p v r r e t e f o l h . i b o e . l l p . e e e f " " m r u s s n — c ( i t u n i n c o d l n e u " r d s i t n a g n d f i u n t g u r y e o u y r o u c — o w d i e l ) l , b a e n d g r i a t t e n f e u e l d . s m a i n t e n a n c e ( u p d a t e s w i t h c o d e c h a n g e s ) .