Tips &Tricks

node 0

How to run cli/unix commands from nodejs scripts?

There are two ways to do this: child_process.exec(command[, options][, call­back]) // ls.js const { exec } = require(‘child_process’); exec(‘ls –lh /usr’, (error, std­out, stderr) => { if (error) { console.error(‘exec error: ${error}‘); return; } console.log(‘stdout:…