INTRODUCTION TO NATIVE ADDONS / NATIVE MODULES

A simple guide to load C/C++ code into Node.js JavaScript Applications

In this article, we are going to get ourselves familiar with the mechanism and tools to load the C/C++ code dynamically in JavaScript programs using Node’s N-API.

Uday Hiwarale
JsPoint
Published in
23 min readDec 5, 2019

--

(Source: unsplash.com)

Before we begin with this tutorial, let me start with a little disclaimer. I am not a professional C and C++ programmer. But I always wanted to use some of the public C++ libraries inside JavaScript code for performance reasons. Then I stumbled upon Native Addon feature of Node.js.

In this article, I will walk you through step by step process of creating node modules written in C++ language. If you spot any errors in the definition or explanation of some native concepts, inform me through private notes so that I can fix the as earliest.

What is a Native Addon?

Before we jump into building Native Addons, we need to know first what they are? A Native Addon in the context of the Node.js is a binary file that is compiled from a low-level language like C and C++. Hence like importing a JavaScript file using require, we would be importing a Native Addon.

--

--