0

I have a Node Express server that works on localhost. It uses child_process to run a C++ standalone executable.

The code that uses child_process is the following (the application creates output.txt):

app.post('/generate', async function(req, res)
{
    var input1 = req.body.input1;
    var input2 = req.body.input2;

    var execFile = require('child_process').execFile;

    var program = "path/to/executable";
    var args    = [input1, input2];

    var child = execFile(program, args,
        function (error, stdout, stderr){           
            console.log(error);
            console.log(stdout);
            console.log(stderr);

            const file = __dirname + "/output.txt"
            app.get('/output.txt', function (req, res) {
                res.sendFile(path.join(__dirname + '/output.txt'));
            });
            res.send("/output.txt");
        })
})

This works locally.

I'm now trying to deploy it on Google Cloud Platform with App Engine.

However, when I go the website that I host, and launch this POST /generate request, I don't get the expected output. In the Google Cloud Platform logs of my project I can see the following error:

 textPayload: "{ Error: spawn cpp/web_cpp_app/x64/Debug/web_cpp_app ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
" 

At first I didn't understand the error, but now I can see that if I locally run the same project, but set the path of the standalone executable to an invalid path, I get the same error. I'm guessing that when I deploy, my executable is somehow not included?

Is there something specific I need to add in package.json or app.yaml files, to include the executable?

EDIT: Could it be that the app engine runs on Linux, and my executable is for Windows?

remi
  • 937
  • 3
  • 18
  • 45

2 Answers2

1

You are right about the OS, per this Doc Appengine standard for NodeJS uses Ubuntu OS, and flexible uses Debian

About the executable compatibility I found this post

Andres S
  • 1,168
  • 7
  • 11
1

ENOENT means "no such file or directory", so your path could be wrong, or the container doesn't recognize the program as executable.

But either way, you will need to build and include a linux-compatible binary of your child_process program in your project directory when you deploy. You could build this manually, or use something like Cloud Build to compile it in a container that's identical to that of App Engine.

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
  • Just for future reference. I ended up using Azure instead Google Cloud Platform; they allow to create Windows server, not only Linux. As far as I know, GCP only has Linux webapp servers. – remi Oct 08 '19 at 10:52
  • All major cloud providers support Windows servers, which includes GCP and AWS. – Travis Webb Oct 13 '19 at 00:53
  • Ok, I was not able to find that from GCP. Possibly because I was only looking at the free services..? – remi Oct 13 '19 at 11:17
  • You can run them on GCE and GKE, just not Appengine – Travis Webb Oct 13 '19 at 15:31