Contributing to Node.js Core
Jarrod Connolly -
(Updated: February 21, 2021)
I had always wanted to contribute to a large open-source project like Node.js but found it daunting to find a place to start. One day while playing with N-API native addons, I finally found somewhere to contribute. My addon required me to create and check Date objects though that functionality appeared missing from N-API.
What is N-API?
N-API allows developers to write native addons to Node.js in C or C++
The Node.js documentation describes N-API as follows.
The N-API is a C API that ensures ABI stability across Node.js versions and different compiler levels. A C++ API can be easier to use. To support using C++, the project maintains a C++ wrapper module called node-addon-api. This wrapper provides an inlineable C++ API.
A great introduction to building a native module using N-API and the
node-addon-api C++ wrapper.
The Node.js project has a great deal of documentation around the process of making and submitting a change. I started reading and preparing my local environment to add new code and run the unit tests. The following documents helped me to get started and follow the correct process.
Provides several links to the information needed to get set up and start working on your changes.
How to set up your local development environment, and the pull request process. Contains a wealth of information such as commit message guidelines and how to keep your branch in sync with upstream. I read this document many times during the process of making my changes.
How to generate a working build of Node.js and run the unit tests.
Node.js C++ style guidelines, idioms and use of language features.
Not needed for doing N-API work but contains detailed information on the C++ code at the core of the Node.js project.
I followed the steps outlined in the documentation to fork the project and get my branch building. I could then run the unit tests and begin adding the missing feature that I wanted to add.
I ended up adding three functions to allow usage of the Date object from N-API.
This API checks if the
Object passed in is a date.
Describes how Node.js collaborators will review your changes. I found this valuable to understand the process from the side of the reviewers.
I opened my pull request on February 4th, and it landed in master on February 28th as 13b1aaf. Feedback came quickly which made for a consistent and smooth process. You can see how the process went as the Node.js team reviewed my code and gave feedback and comments.
My change became a part of N-API version 4.
Node.js v11.11.0 contained my Date object addition to N-API. A later backport included it in v10.17.0
I learned a great deal during my experience and overcame the fear of contributing to larger open-source projects. I always looked up to and respected the Node.js members who reviewed my pull request. I had looked up to them like rock stars, having them review my code with welcoming professionalism made for a rewarding experience. Later that year while attending the Node+JS Interactive conference I had the chance to thank many of them in person.
I recommend that anyone who feels that they have something to contribute to any open-source project gives it a try. More often than not, project maintainers will provide guidance and work with you to land your changes.
Looking forward to landing more changes in Node.js core as soon as possible. I also hope everyone else can contribute to open-source projects where their expertise or area of interest takes them.