All Projects → davidgatti → How-to-use-C-in-NodeJS-through-CPP

davidgatti / How-to-use-C-in-NodeJS-through-CPP

Licence: MIT License
🤓 How to write C code in NodeJS using C++ as a pass through?

Programming Languages

C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language
python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to How-to-use-C-in-NodeJS-through-CPP

science-fiction-magazines-blog
Blog template (concept) is inspired by stylish science fiction magazines of the 80-90s.
Stars: ✭ 24 (-52%)
Mutual labels:  article
python-for-data-and-media-communication-gitbook
An open source book on Python tailed for communication students with zero background
Stars: ✭ 99 (+98%)
Mutual labels:  communication
pulseha
PulseHA is a active-passive high availability cluster daemon that uses GRPC and is written in GO.
Stars: ✭ 15 (-70%)
Mutual labels:  communication
yahdlc
yahdlc - Yet Another HDLC implementation
Stars: ✭ 47 (-6%)
Mutual labels:  communication
bundler-comparison
Comparison of web resource bundlers. 📦
Stars: ✭ 21 (-58%)
Mutual labels:  article
OpenWeatherDemo
Demo app for the article as published on the Delphi Worlds blog
Stars: ✭ 17 (-66%)
Mutual labels:  article
startuptoolbox
The startup founder toolbelt. A forever-updating crowdsourced collection.
Stars: ✭ 146 (+192%)
Mutual labels:  communication
blog
博客,基于issues,技术和思考请参看 https://trello.com/b/fZ2i0xjA
Stars: ✭ 29 (-42%)
Mutual labels:  article
learning-growth
主要是我的一些阅读、学习、社交、研究、思考、放松娱乐记录整理。
Stars: ✭ 73 (+46%)
Mutual labels:  communication
wechat
WeChat for Jenkins (Jenkins 官方微信公众号)
Stars: ✭ 20 (-60%)
Mutual labels:  article
unkillable-scratch
Disallow the *scratch* buffer from being killed
Stars: ✭ 13 (-74%)
Mutual labels:  buffer
p3270
A python library to take control of remote IBM hosts
Stars: ✭ 32 (-36%)
Mutual labels:  communication
webflux-streaming-demo
A tryout of reactive application using Spring 5 WebFlux and mongoDB, along with an overview article on reactive programming.
Stars: ✭ 96 (+92%)
Mutual labels:  article
popc
Popc manager for vim & neovim
Stars: ✭ 17 (-66%)
Mutual labels:  buffer
awesome-technical-communication
😎 A curated list of awesome resources about technical communication
Stars: ✭ 102 (+104%)
Mutual labels:  communication
L2-Emulator
Implementing a Layer-2 Emulator in C using Graphs and LinkedList
Stars: ✭ 17 (-66%)
Mutual labels:  communication
openHAB-Simatic
openHAB binding for Siemens Simatic S7 PLC
Stars: ✭ 15 (-70%)
Mutual labels:  communication
k8s-log
容器日志搜集套件。
Stars: ✭ 15 (-70%)
Mutual labels:  buffer
graphql-io
GraphQL Network Communication Framework
Stars: ✭ 41 (-18%)
Mutual labels:  communication
AstroMech
Protocol for exchanging small amounts of data over audio.
Stars: ✭ 21 (-58%)
Mutual labels:  communication

C in NodeJS through C++

Using C or C++ in NodeJS is more of an edge case than daily life. But I decided to put down what I learned because there is little information on the Internet about this topic. My goal is to focus on simple example, so you can focus on how to send data to and receive data from C/C++ and NodeJS. Once you understand this concept, you'll be able to write your own low-level code or take advantage of faster libraries to process your specific information.

Quick ground rules

Keep in mind that buffers are the simplest way to communicate between the two worlds. You just create a blob of data that can be sent through any means of communication, and on the other end, you can integrate it however you want. You are not sending a specific type that you then need to match at the other end.

And since buffers are just dumps of raw bytes, any language will be able to handle them. The steps to create a successful app:

  1. Prepare a buffer in NodeJS
  2. Send the buffer to C++ using a function exposed to NodeJS from C++
  3. Access the buffer and save it in a variable of the right type
  4. Do something with the data
  5. Send the computed result back to NodeJS

WARNING: The V8 API is constantly changing

V8 is the environment used by NodeJS to process JavaScript files. This environment is written in C++; therefore, we can use C++ in our project 🛎. The downside of V8 is that Google has very poor documentation for it, and to make it even worse, a new version of V8 won't necessarily be compatible with the previous one.

That's why we have to hug 🤗 the hard working team of the Nan module for NodeJS, which basically wraps V8 in a consistent API, thus making our life much easier.

How to use this repository

This repo has a bunch of directories containing fully working code that showcases how to do one thing only. With this approach, you can more easily see how to handle different situations.

Each directory has its own README.md file explaining how to run the project and, possibly, additional information about some caveats to be aware of.

The book that made me understand

The book C++ and Node.js Integration by Scott Frees, Ph.D was an important aspect of learning to use C libraries with NodeJS. If you want take this subject seriously, you should definitely check this book out. It talks in greater detail about more stuff than this article can cover. What I'm writing is more of a template, a reminder of what I learned. It should help you get started, but if you would like to go deeper, that book is fantastic.

The End

If you enjoyed this project, please consider giving it a 🌟. And check out my GitHub account, where you'll find additional resources you might find useful or interesting.

Sponsor 🎊

This project is brought to you by 0x4447 LLC, a software company specializing in building custom solutions on top of AWS. Follow this link to learn more: https://0x4447.com. Alternatively, send an email to [email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].