Search code examples
node.jsherokubuildpack

Running child c executable as child process in node.js heroku app


I want to run c program as child process in node.js on heroku. In my app.js:

app.get('/extra', function (req, res) {
    const child = spawn('./a');
    child.stdin.setDefaultEncoding('utf-8');
    child.stdin.write(52 + "\n");
    child.stdin.end();

    child.stdout.on('data', (data) =>{
        const dataString = "" + data;
        res.send(dataString);
    });
});

I am using heroku c-buildpack with Makefile: all: gcc main.c -o a.out It logs successful, but when I get /extra app fails, and when I tried to list all files with fs.readdirSync('/').forEach... it only logged app.js


Solution

  • switching

    spawn('./a') 
    

    to

    spawn('./a.out') 
    

    fixed the issue