A Quick Guide To Reading Node.js Core Source
Here’s how I’ve approached understanding the source code that makes up Node.js core. This is what has worked for me. Your mileage may vary. Warranty void if seal is broken.
The source code can be found at https://github.com/nodejs/node.
Here we go!
- Make sure you understand Node.js a little bit. I mean, you know, do a few simple programs first before looking at core. Presumably, you’ve done that, so let’s move on.
- Start with the docs for APIs. Pick one you are particularly interested in and read through it. Or read through all of them. At the time of this writing, these documents can be found at https://nodejs.org/dist/latest-v5.x/docs/api/. Or you can read the markdown directly in the source tree at https://github.com/nodejs/node/tree/master/doc/api. Or you can read them from the `doc/api` directory in your local copy of the source code.
- There is an excellent chance that by now, you have found a small typo, omission, or other problem with the docs. Hey! This is an opportunity to get familiar with the Node.js contribution process. You can skip this step if you just want to understand the code only and not participate in the project. But otherwise: Read up on how to submit a change at https://github.com/nodejs/node/blob/master/CONTRIBUTING.md.
- Remember step 2 where you read some docs for APIs? Now it’s time to read the source for the API that interests you. Let’s say you’re all about `http`. Look in `lib/http.js`. When you come across stuff you don’t understand — what is `process.binding`? — look it up in the docs. Or ask on the #node-dev channel on freenode.
- Whatever you were looking at (let’s say `http`), now read all the tests for that in `test/parallel` and `test/sequential`.
At this point, there’s still a lot of stuff that hasn’t been covered. But hopefully you’ve got a good start. Or maybe this is a terrible script for you and you will try something else and write your own Medium post and it will make this one obsolete. Surely, it will have a better concluding paragraph than this one.