Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 453 Bytes

run-c++-code-from-nodejs.md

File metadata and controls

24 lines (17 loc) · 453 Bytes

Run C++ code from NodeJS

// myCFile.c #include <stdio.h>

int main(void){

// Processor-intensive computations
int x = 1+2+3;

// Send to node via standard output
printf("%d", x);

// Terminate the process
return 0;

}

Compile: gcc -o myExecutable myCFile.c

And use child_process like this // File myNodeFile.js const { exec } = require("child_process"); exec("./myExecutable", (error, stdout, stderr) => console.log(stdout));