Node.js Addons

Learning C++ addons for Node.js

  • Cross-platform addons with node-pre-gyp - 02/07/2017

    Node.js applications (including electron apps) are deployed everywhere, including end-user machines without a full development stack. Usually this is no problem - but things get complicated with native addons are used.

    Native C++ addons are distributed as modules, but npm builds them on the target machine during the install using node-gyp. node-gyp isn’t a compiler, it’s a build system that adapts to the platform it’s on - on Windows it will use Visual Studio and on Linux/macOS it will use g++/clang. When installing an addon on a machine without a compiler, we are out of luck.

  • Streaming data into a Node.js C++ Addon - 12/30/2016

    Earlier this year I posted an article showing how we can build event-based and streaming interfaces for sending data from Node.js C++ addons to JavaScript. This mode of interacting with addons can be a lot easier in some situations, especially when your C++ code runs asynchronously.

    In this post, I’m going to use the streaming-worker and streaming-worker-sdk modules - which I’ve adapted from the Streaming chapter in my ebook: C++ and JavaScript Integration. In the book, I cover the details of how streaming-worker and streaming-worker-sdk actually works internally - here I’ll just focus on using them.

  • Buffers and C++ on Rising Stack - Community - 10/26/2016

    It’s been a few months since I’ve posted to this blog and I wanted to link to an article I’ve been working on that just appeared on Rising Stack’s new Community blog. The article - Using Buffers to share data between Node.js and C++ is all about making use of Buffers to efficiently move data between JavaScript and C++ - including asynchronous addons with worker threads..

  • C++ Addons as AWS Lambda functions - 08/17/2016

    In this post I’m going to walk you through creating and deploying a Node.js AWS Lambda function that uses a native C++ addon. As you’ll see, the process isn’t much different than creating normal AWS Lambda functions with Node.js - you’ll just need to get your development environment to match the requirements for AWS.

  • Streaming data from C++ to Node.js - 07/20/2016

    If you’ve worked with C++ addons for Node.js before, you know there’s a lot of work that goes into making them play well with the rest of your JavaScript program. Once you learn how to keep up with V8 changes using NAN and how to deal with C++/JavaScript data type conversions, you also need to deal with asynchronous addon functions. The asynchronous pattern - which I’ve posted about before - is tricky, to say the least. Using the asynchronous pattern lets Node.js code call into C++ and receive data through a callback - allowing the C++ addon to do it’s work inside a separate thread. This allows the addon code to run on the CPU for long stretches without tying up Node.js’s event loop - a big win.

  • C++ and Node.js Integration - eBook Published - 06/17/2016

    I’ve got good news, I’ve finally completed the C++ and Node.js Integration ebook! I want to thank all of you for signing up for my newsletter to keep posted about the book - you kept me motivated!  Thanks also to all the people who reached out to me with ideas, tips, and insights into the topic - you were extremely helpful.

  • Type conversions from JavaScript to C++ in V8 - 04/02/2016

    Learning how to pass information from JavaScript to C++ addons can be tricky. Confusion stems from the extreme differences between the JavaScript and C++ type system. While C++ is strongly typed (“42” is not an integer… it’s a string, and only a string!), JavaScript is very eager to convert datatypes for us.

  • How (not) to access V8 memory from a Node.js C++ addon's worker thread - 02/01/2016

    When we create C++ addons for Node.js, we have two strategies - synchronous or asynchronous processing. A synchronous C++ addon does it’s number crunching in the thread that Node.js’s event loop executes in. This, unfortunately, blocks all JavaScript execution until the C++ addon completes it’s work and returns control back to JavaScript. In asynchronous addons, we can execute the heavy lifting in a worker thread. This allows the initial call into the addon to return quickly to JavaScript - freeing up the Node.js event loop to continue it’s business.

  • Async Addons with Nan for the New Year (and eBook content updates) - 01/04/2016

    Happy New Year everyone! Last month I let you all know I was starting a blog series about Getting C++ to the Web using Node.js. My plan was to get the whole series out by the end of the year, and I just made it! The last part was posted just a couple of days ago, it focused on asynchronous addons using Nan. I also covered automation and shared libraries along the way.

  • Building an Asynchronous C++ Addon for Node.js using Nan - 12/31/2015

    This post is the fourth and final in a series dedicated to showing you how to get your C++ application onto the web by integrating with Node.js. In the first post, I outlined three general options:

  • Calling Native C++ DLLs from a Node.js Web App - 12/29/2015

    This post is the third in a series of four posts dedicated to showing you how to get your C++ application onto the web by integrating with in Node.js. In the first post, I outlined three general options:

  • Automating a C++ program from a Node.js web app - 12/16/2015

    This post is the second in a series of four posts dedicated to showing you how to get your C++ application onto the web by integrating with Node.js. In the first post, I outlined three general options:

  • Getting your C++ to the Web with Node.js - 12/03/2015

    So, you’ve got some old C or C++ code, playing an important role in your business - but you desperately want to get that functionality on the web - maybe just internally to streamline your workflow, or maybe publically in order to fulfill some other goal. The problem, of course, is that C++ isn’t exactly easy to put onto the web - so what are your options?

  • C++ processing from Node.js - Part 4 - Asynchronous addons - 08/07/2015

    This article is Part 4 of a series of posts on moving data back and forth between Node.js and C++. In Part 1, I built up an example of processing rainfall accumulation data in C++ and returning a simple statistic (average) back to JavaScript. In Parts 2 and 3, I covered more complex use cases involving moving lists and objects. This post covers asynchronous C++ addons - which are probably the most useful.

  • C++ processing from Node.js - Part 3 - Arrays - 07/20/2015

    This article is Part 3 of a series of posts on moving data back and forth between Node.js and C++. This series is also expanded upon in my ebook on Node/C++ Integration. In Part 1, I built up an example of processing rainfall accumulation data in C++ and returning a simple statistic (average) back to JavaScript. In Part 2 I modified the C++ addon to return a JavaScript object representing more complete statistics about each location/sample.

  • C++ processing from Node.js - Part 2 - Objects - 06/29/2015

    This article is Part 2 of a series of posts on moving data back and forth between Node.js and C++. In Part 1, I built up an example of processing rainfall accumulation data in C++ and returning a simple statistic (average) back to JavaScript.

  • C++ Processing from Node.js - 06/17/2015

    I love doing high-level work in node.js, but sometimes I’m working on data analysis that needs to be done in a higher performance language. C++ is usually a good choice for these tasks, and a great thing about node is how easy it is to move data to and from C++ with the node’s addon mechanism - using the V8 API. There’s a lot of documentation on the node site, but I’ve found it hard to locate full examples where there are full data structures flowing between JavaScript and C++… so I wrote this.

Looking for more?

Sign up to for Node Addons newsletter so you find out when new articles are published right away. With your signup, you'll get a free copy of Chapter 2 - Understanding V8 Programming from the Node and C++ Integration e-book

* indicates required