Node.js Addons

Learning C++ addons for Node.js

C++ and Node.js Integration

The popularity of Node.js just keeps surging, it's great for so many things. But what if you need serious C/C++ speed? What if you want to move to Node.js, but can't afford to rewrite your existing C++ code?

Buy now!

The good news...

Fear not... you can overcome your speed or legacy code problem by writing native C++ addons for Node.js! Once you know how, you can call your C++ code right from your Node.js code - easily and cleanly.

The bad news

Learning the complex C++ API for addon development is hard. Answers are spread across a few blog posts and terse documentation. If you are looking for a step-by step and simple explanation, you'll be looking for a long time! Worse yet - since the V8 API changes so frequently, it's hard to blend all these resources together in a comprehensible and consistent way.

The solution

That's what this book is all about - I've put together a comprehensive manual for creating your C++ addon. Ranging from simple synchronous examples, asynchronous C++ modules and object oriented designs, to defending yourself against changing API's - "C++ and Node.js Integration" will get you to the finish line. And it will save you weeks of research time!

Want the book?

Buy Now! For $24.99 you'll get the ebook (PDF, HTML and epub) containing over 200 pages of text describing dozens of addons, along with all the example code listings.

Need help deciding?

Sign up to for my newsletter on Node.js integration. With your signup, you'll get a free copy of Chapter 2 - Understanding V8 Programming!

* indicates required

Table of Contents

This book is a major expansion on a four-part series on my blog on building C++ addons for Node.js. I've expanded each of the topics into full chapters, and added four completely new chapters. The book also contains more code examples, and coverage of the latest V8 API changes.

Chapter 1: Introduction to Node.js Addons

Learn the basics of creating Node.js Addons and how to use node-gyp to create and test them. We'll go through a few quick examples, and outline the rest of the book.

Chapter 2: Understanding the V8 API

Learn about the C++ underpinnings of Node.js and how it all works. You'll see why Node's interface with C++ is so efficient, and how V8's design effects how you write your addons. In this chapter we'll cover all the V8 data types, and how the V8 memory system can be accessed from C++.

Chapter 3: Basic Integration Patterns

See how to create your first full-featured C++ addon and pass JavaScript objects to C++. We'll look at turning your JavaScript objects into first-class objects matching a C++ class definition and how to return data back to Node.js.

Chapter 4: Asynchronous Addons

What good is a Node.js module if it blocks your event loop? In this chapter you'll learn how to do the heavy computational task you've written in C++ asynchronously. Just give your C++ code a JavaScript callback function, and your JavaScript can just keep on running until the C++ is done.

Chapter 5: Object Wrapping

If you have existing C++ classes that you want to be able to use as "native" JavaScript objects, then you'll need to learn to wrap your C++ classes with V8 data structures.

Chapter 6: Native Abstractions for Node (NAN)

The V8 API has undergone many "breaking" changes - and since different version of Node.js use different versions of V8, the situation can get pretty complex to manage. This chapter will show you how to work at a higher level of abstraction using Nan - the Native Abstractions for Node.js library. Using Nan, you'll defend yourself from the changing V8 API.

Chapter 7: Streaming between Node and C++

Learn how to build great interfaces to your C++ addon by supporting an event emitter and streaming interface for both sending data to you addon, and returning a data asynchronously to JavaScript.

Chapter 8: Publishing Addons

Publishing your typical Node module to an npm repo is pretty simple - but since your C++ is native executable code, there are some hoops you'll need to jump through so your addon works on all operating systems. In this chapter, we'll cover solutions to common pitfalls involved in publishing/deploying C++ addons.

Appendix A: Getting your C++ to the Web

Addons aren't the only way of moving C++ to the web - in this section we'll take a look at some of the other options, like automation and shared libraries.

Appendix B: Buffers

One of the most efficient ways to move data between JavaScript and your C++ addons is by using buffers - which get stored outside V8's memory. In this section we'll go through an image processing example that uses buffers to convert pixel data from PNG to BMP.

Want to share it with your team?

Save your developers' time by sharing this book with your team. You can purchase a team license that covers up to 50 developers for $99.99, or corporate license if you belong to an even bigger team.

Team (up to 50 users) Corporate (entire organization)

Do I need to be a JavaScript or C++ expert?

Absolutely not - this book doesn't assume JavaScript or C++ mastery, only working knowledge. In all examples and discussion, advanced topics in JavaScript are only presented when necessary - and always explained.

All C++ code examples are approachable to the C++ novice. Seasoned C++ vets will see where things could be written differently, using more advanced C++, without changing the spirit of the discussion.

My goal is to show you how to integrate - not how clever JavaScript or C++ code can be.

Can't I find this information on my own?

Most programmers learn new topics by scouring the web, piecing together SO posts and API docs to boost their skills.

It normally works pretty well, but once you spend some time researching the V8 C++ API docs, you'll realize that C++ addons are a different animal. Information is scarce, and often refers to out-of-date API's. You find yourself at dead-ends and hitting one roadblock after another.

I went through this pain - and that's why I think this book is worth buying - it will save you from it!

Want the book?

Buy Now! For $24.99 you'll get the ebook (PDF, HTML and epub) containing over 200 pages of text describing dozens of addons, along with all the example code listings.

Need help deciding?

Sign up to for my newsletter on Node.js integration. With your signup, you'll get a free copy of Chapter 2 - Understanding V8 Programming!

* indicates required

About Me

I am a Professor of Computer Science at Ramapo College of New Jersey, specializing in computer graphics, and web development. I'm also a consultant and freelance developer, with over ten years of professional experience.

As a professional and as a scholar, I provide innovative solutions in a diverse set of fields - including mechanical engineering, computational biology, environmental science, and organic chemistry.

I teach Web Application Development, Operating Systems, Computer Graphics, Database Systems, and a number of other courses at Ramapo College.

What others are saying....

comments powered by Disqus