-3

I have a web application written in nodejs which needs to communicate with C binary to fetch and set some details, any idea on how to approach this?

Edit: Because the question is too broad i will give an example

consider this c program -> test.c

#include <stdio.h>
int main(b){
  int a = 5; 
  return a+b;
}

now i want to execute this test.c from Nodejs and pass in the vaule of b(say b=5) and retrieve the final result as 10

Pavan Skipo
  • 1,757
  • 12
  • 29

1 Answers1

2

There's a whole lot of a way to handle that.

For instance :

  • Start the C program as a server, and listen to JSON/binary/XML/whatever message from your nodejs app. You can even use HTTP if you wish, or listen to a Unix Socket.
  • Start the program directly from the nodejs app, pass the arguments as parameters to the C program or using stdin.
  • Write the parameters in some file, and pass the file path to the C program, or make the C program watch the directory and do the stuff you want it to do.

There's no better way than another, it just depends on what you need, how many initialization stuff the C programs need to do, if it runs on the same machine...

blue112
  • 52,634
  • 3
  • 45
  • 54