ipc          nodejs <-> C interprocess communication library
------------------------------------------------------------
Source Code (Github)

This library enables your nodejs programs to exchange
messages with C programs by using unix sockets.

In order to use this library, you should first compile your
C program and create an executable. Then by using the file
path of executable, nodejs program can spawn that process
and connect to it like this

IPC = require("ipc.js") IPC.connect("path-of-your-c-executable")
messages can be sent from nodejs to C
IPC.send("sample message")
messages that sent from C can be consumed in nodejs
IPC.onmessage = function(msg){ console.log(msg) }
main function of your C program should call ipc_start to start a blocking event loop that listens the messages coming across the unix socket, you must also pass the argc and argv parameters of main function to ipc_start alongside with a function pointer onmsg that handles the messages sent from nodejs
int32_t main(int32_t argc, int8_t* argv[]) { ipc_start(argc, argv, onmsg); return 0; }
message handler takes 2 self-explanatory parameters msg and size you can also use the function ipc_send to send messages from C to nodejs
void onmsg(uint8_t* msg, uint32_t size) { printf("received msg with size %d\n", size); ipc_send({65, 66, 67, 68}, 4); }
To sum up, this library has 3 library files and 1 example folder 1. ipc.c C ipc library implementation 2. ipc.h C ipc library header file 3. ipc.js nodejs module for ipc library In order to see a sample usage check the example folder 1. Run the compile.sh to generate executable 2. Run node test.js