Online Compiler using Nodejs

Online Compiler using Nodejs
0.0 0

#1

Actually I am trying to create an online compiler like ideone, sapphire-engine etc using nodejs for C/C++.
But I haven’t found a way to compile the code on the server side. Basically I want to send my code using POST method to the server and I want node to use GCC compiler and compile the code and send the output back as the response but I don’t know how to make GCC available to node. I mean how to add the C/C++ compiler to nodejs


#2
  1. User submits code
  2. Have Node write the code to a file (or files?) using the fs module.
  3. Notify the user that the app is about to start compiling
  4. Use exec (or spawn) from the child_process module to execute GCC using the correct CLI arguments, passing it the file you’ve just created.
  5. Notify the user that compilation has succeeded or failed.
  6. You should have a binary on the local filesystem at that point, so if successful, do something with it.

There will be more involved ways of expanding on this and making it more robust (maybe you have a Makefile or whatever, and that’s the thing that gets executed rather than GCC directly), but that might give you a good basis; effectively all you’d be using Node for is to pass messages from user to and from the OS and filesystem on the server.

fs module for working with the filesystem:

https://nodejs.org/api/fs.html

child_process module for spawning and executing child processes:

https://nodejs.org/api/child_process.html


#3

Thanks!
I will try that.