Reading the source beats reading the docs
Docs tell you the happy path. The source tells you what actually happens when you leave it.
I lost most of a day last week to a caching bug. The docs for the library said the cache key was derived from the request URL. That was true, but incomplete: it also folded in a header I was setting dynamically, so my cache hit rate was effectively zero.
None of this was written down. All of it was thirty lines into a file I could have opened at any point.
The habit worth building
When a library behaves in a way you didn't predict, open node_modules before you open a search
engine.
You already have the exact version you're running, which is more than any blog post or Stack Overflow answer can promise you.
// The fastest way to find where you actually are
console.log(require.resolve('the-library/package.json'));From there, d.ts files are usually the highest signal-per-line reading in the whole
package. They're the author's own summary of what the thing does.
What you get out of it
- Version-accurate answers. No guessing whether the post you're reading predates a rewrite.
- The edge cases. Docs describe the happy path because that's what docs are for.
- Better bug reports. "This throws at
cache.ts:112whenheadersis undefined" gets fixed a lot faster than "caching seems broken."
The obvious caveat
Reading the source tells you what the code does today, not what it promises to keep doing. If you depend on something you found in there and not in the docs, you've depended on an implementation detail. Write a test that will tell you when it moves.
It's not a substitute for good documentation. It's just that the source is always there, always current, and nobody forgot to update it.