I have to write Node.js script using promise.all() that will check that environment has docker, git, npm, nvm and node.js. For every tool write to stdout the tool version. If some tools doesn't exist write to stderr message about it and finish process with right exit code.
My code is look like this:
const util = require("util");
const exec = util.promisify(require("child_process").exec);
async function getVersion(env) {
try {
const { stdout } = await exec(env);
console.log(stdout);
} catch (error) {
console.error(error.stderr);
}
}
(async function () {
const fileVersion = [
"node --version",
"docker --version",
"nvm version",
"git --version",
"npm --version",
];
const results = await Promise.all(fileVersion);
for (const element of results) {
getVersion(element);
}
})();
I know that in that code promise.all() is not playing any role, I'm not familiar with promise.all() and please anyone could show me an example how to do it?