0

First of all, let me just say I am new to backend dev and Google Cloud App Engine. I have created a REST API using koa.js (very similar to express.js in this basic example). I have created one method which creates a child process. The child process executes a file. Here is what my code looks like:

const { execFileSync } = require('child_process');
const Router = require('koa-router');
const CONVERTER_PATH = '../../libraries/converter/converter.exe';

const router = new Router({
     prefix: '/converter'
});
router.post('/convert', (ctx, next) => {
    execFileSync('start ' + CONVERTER_PATH);
    ....
    next();
});

Here are the contents of the app.yaml file:

runtime: nodejs16

When I serve this locally, the '/convert' method works correctly and throws no error. However, when I deploy to Google Cloud App Engine using 'gcloud app deploy', and call the method, it throws the following error:

Error: spawnSync start ../../libraries/converter/converter.exe ENOENT
     at Object.spawnSync (node:internal/child_process:1119:20)
     at spawnSync (node:child_process:847:24)
     at /workspace/router/converter/index.js:18:3
     at dispatch (/workspace/node_modules/koa-compose/index.js:42:32)
     at /workspace/node_modules/koa-router/lib/router.js:425:16
     at dispatch (/workspace/node_modules/koa-compose/index.js:42:32)
     at /workspace/node_modules/koa-compose/index.js:34:12
     at dispatch (/workspace/node_modules/koa-router/lib/router.js:430:31)
     at dispatch (/workspace/node_modules/koa-compose/index.js:42:32)

I tried debugging the issue. I added a line of code that executes the 'dir' command to the '/convert' method and the directory looks exactly the same when served locally and on App Engine. The path '../../libraries/converter/converter.exe' appears to exist just the same locally and on App Engine. I also tried adding the following to app.yaml:

runtime_config:
     skip_lockdown_document_root: true

Not sure what this is supposed to do (saw in a different post) but this seemingly had no effect.

Any idea why the method is behaving differently when I deploy to App Engine? Thank you in advance for the help!

  • ```ENOENT``` usually means it can't find the referenced file. In your example, it would most likely mean it can't find ```../../libraries/converter/converter.exe```. You said in production, the path ```./../libraries/converter/converter.exe``` exists. How did you verify that? – NoCommandLine Apr 11 '23 at 21:26
  • Thank you for the response. I used the 'exec' function from 'child_process' to execute the 'dir' command. 'libraries' exists in the root directory. Then I did the same thing again, except I changed the working directory to 'libraries', there was a folder called 'converter' within 'libraries'. I did this a final time, changing the working directory to 'libraries/converter' and there was a file called 'converter.exe' in 'libraries/converter'. So, the file tree appears to be the same locally and on App Engine. I think the issue is related to App Engine (or my lack of App Engine knowledge). – user18548545 Apr 12 '23 at 00:18

1 Answers1

0

I figured out the problem. I could have sworn you could configure App Engine to run Windows (and thought I did so) but this is false. App Engine standard only runs Ubuntu and App Engine Flexible runs Desbian. Refer to this question: child_process in Node js Google App Engine.