I have a node.js and express script that is taking a file, running a script on it, and returning stdout to the console log. Instead of logging the stdout to the console, i would like to send the output (which is in JSON) back to the client in a response. I'm seeing that maybe res.send is the proper way to do this. Is this the correct method and where would this go in my code?
const multer = require('multer')
const fs = require('fs')
const exec = require('child_process').exec
const express = require('express')
var app = express();
const upload = multer({
    dest: './upload',
    fileFilter: function (req, file, cb) {
        if (file.mimetype != 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
            return cb(new Error('Wrong file type'))
        }
        cb(null,true)
    }
}).single('file');
app.post('/upload', upload, function(req, res) {
  const filePath = req.file.path
  exec(`./script.sh ${filePath}`,
      function (error, stdout, stderr) {
          console.log(stdout);
          if (error !== null) {
              console.log('exec error: ' + error);
          }
          res.setHeader('Content-Type', 'application/json');
          res.send(JSON.stringify({ test: 'test' }));
      });
});
 
    