A 6-Step-Guide for Contributing to the Node.js Core

RisingStack's services:


Node.js Experts

Learn more at risingstack.com

Sign up to our newsletter!

In this article:

The aim of this article is to help you land your first commit to the Node.js core!

Contributing to Node.js can be done in a lot of different ways. You can start contributing to one of the working groups (like the Website, Diagnostics or Post-mortem group) or start teaching at Nodeschools, so your peers can learn from you.

You can also start working directly on the Node.js Core, whether you do it by answering questions, or actually adding code to the project.

The 6 Necessary Steps for Building the Node.js Core

In the next chapters, you will learn in-depth what are the necessary steps to start committing code for fun and profit!

#1 Fork the Project

To get started, head over to the official Node.js repository, located at https://github.com/nodejs/node, and fork the project to your Github account.

Contributing to the Node.js Core - Fork

#2 Setup your git Repository

Once you have your very own repository, head over to your terminal and clone the project.

$ git clone git@github.com:YOUR_USER_NAME/node.git

Then enter the directory using cd node.

Keep in mind that once you start developing your changes to Node.js, others won’t stop either! The repository you forked will keep accepting new commits, and yours will get behind.

To keep your fork up-to-date, you have to set up an other origin to pull commits from. To do so, run the following command in your terminal which will setup a remote called upstream.

$ git remote add upstream https://github.com/nodejs/node.git

After setting up upstream, you can run the following command once in a while to get the latest commit from the official Node.js repository:

$ git pull upstream --rebase

# it will produce an output similar to this one
remote: Counting objects: 9150, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 9150 (delta 5908), reused 5917 (delta 5908), pack-reused 3231
Receiving objects: 100% (9150/9150), 6.71 MiB | 2.06 MiB/s, done.
Resolving deltas: 100% (7343/7343), completed with 3204 local objects.

#3 Build your Node.js Binary

Now you have the project cloned in the right way, so it is time to build the binary of Node.js locally!

To do so, make sure you have GCC and Clang (or Visual Studio if you are on Windows), Python 2.6 or 2.7 and GNU Make installed.

To build Node.js, run the following commands:

$ ./configure
$ make -j4

Running make with the -j4 flag will cause it to run 4 compilation jobs concurrently which may significantly reduce build time.

Once it finishes, you can run your locally built Node.js using:

$ ./node --version

More information on supported platforms and building the project can be found here: https://github.com/nodejs/node/blob/master/BUILDING.md

#4 Write tests, Run the Tests

Test files are named using kebab casing.

  • The first part of it is test.
  • The second is the module you are going to test.
  • The third is usually the method or event name being tested.

So if you would write a test case for HTTP requests, probably you would name them something like this: test-http-posting-form-data.js.

Let’s take a look at the following example taken from the Node.js project on how a test file should look like:

In the first line of the test file you should
enable strict mode, unless you test something
that needs it disabled
'use strict';

the common package gives you some commonly
used testing methods, like mustCall
const common = require('../common');

a small description on what you are testing
// This test ensures that the http-parser can handle UTF-8 characters
// in the http header.

const assert = require('assert');
const http = require('http');

the body of the actual test - tests should exit with code 0 on success
const server = http.createServer(common.mustCall((req, res) => {

server.listen(0, () => {
    port: server.address().port,
    headers: { 'Test': 'Düsseldorf' }
  }, common.mustCall((res) => {
    assert.strictEqual(res.statusCode, 200);

To run the tests, you can:

$ make test

Protip for Testing Internal Modules

To test internal modules, you have to require them in your test cases. The problem is that Node.js by default doesn’t let you do that. To do so, run Node.js with --expose-internals flag.

More information on writing tests can be found here: https://github.com/nodejs/node/blob/master/doc/guides/writing-tests.md

#5 Find Something to Work On

As of the time of this writing, there are 563 open issues in the Node.js project. At first, this can be overwhelming for newcomers to pick an issue to work on.

Luckily, there are a few tags in the issue tracker that can help finding you your first contribution.

The first one is called good first contribution, the second is help wanted. I recommend picking one from the good first contribution at first, and once you feel more comfortable working on the project, go for the help wanted label.

#6 Submitting your Solution

Once you developed your features or addition test coverage, just push your changes to your repository, and head over to Github. With your changes pushed, a green merge button will appear at the top. Just open a pull request, and wait other contributors to approve/request changes in your pull request.

With this, you are on your way to become a Node.js contributor. Congratulations, and keep the commits coming!

Share this post



Learn more at risingstack.com

Node.js Experts