How to support async/await when running scripts using npm

because the version of node you are using does not support the async/await feature for the time being
if you run it on the command line and you want it to support the async/await function, it usually runs like this

node --harmony index.js

but if it is executed in npm, such as the following configuration

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "serve": "serve ."
  }
npm run serve

because the serve module uses the async/await function, it will report an error
so how can you easily turn on the function of-- harmony in the configuration file and try not to modify the information in the script configuration

Mar.23,2021

const { spawn } = require('child_process');
const ls = spawn('node', ['--harmony', 'index.js']);
Menu