I'm trying to create an editor like FreecodeCamp and I ran into an interesting problem. I have my frontend sending a string that I then try to convert into a file using the node process writeFileSync. I then try to call a script programmatically using exec from the child_processes module.
const str = req.body.code.replace(/"/g, "");
await fs.writeFileSync('./test/add.js', str)
await exec('npm run test', (error, stdOut) => {
console.log('error', error);
console.log('stdout', stdOut)
res.json({ message: stdOut })
})
})
If I commit out await fs.writeFileSync('./test/add.js', str) it works perfectly. How can I write a file and then run my script?