📚Cheatsheets

Cheatsheet collection for go, rust, python, shell and javascript.

run-command

Exect command line application with nodejs and get the test result back.

const { exec } = require("child_process");

async function runCommand(cmd) {
  console.log('\x1b[32m%s\x1b[0m', "+ " + cmd)
  return new Promise((resolve, reject) => {
    exec(cmd, (error, stdout, stderr) => {
        if (error) {
            reject(error.message)
        }
        if (stderr) {
          reject(stderr)
        }
        resolve(stdout)
    });
  })
}

Usage:

let res = await runCommand("ls -l");