I need to run two shell commands, one-by-one. These commands are wrapped in to functions:
function myFucn1() { exec('some command', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); throw error; } console.log(`stdout: ${stdout}`); console.error(`stderr: ${stderr}`); }); } and
function myFucn2() { exec('some command 2', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); throw error; } console.log(`stdout: ${stdout}`); console.error(`stderr: ${stderr}`); }); } When I am calling them on my trigger function:
app.get('/my_end_point', (req, res) => { try { myFucn1(); myFucn2(); res.send('Hello World, from express'); } catch (err) { res.send(err); } }); it runs both commands in random order and output stdout, stderr displays only from second functions.