I am trying to run an async/await operation to create a new record of a model named Log. I carried out this operation within my child process exec function, but for some reason, the operation does not work since the await operation triggers a syntax error yet it is within an async function.
My child process exec function runs within an async function acting as my handler for an express JS route
const express = require("express")
const router = express.Router()
const cp = require('child_process')
const Log = require('../models/logModel')
router.get("/status", asyncHandler( async (req, res) => {
const cmd = 'pwd'
cp.exec(cmd, (err, stdout, stderr) => {
console.log('#1, exec')
console.log(stdout)
const newLog = await Log.create({
cmd: cmd,
output: `${stdout}`
})
res.status(200).json({log: newLog})
})
}) )
module.exports = router