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!