A truly universal language
But what if…
With one of Google’s latest projects, a CLI-tool simply called “zx”, such a library is now available. Best of all: you can use it right away. All you need is an installed Node.js instance that’s equal to or higher to version 14.
// Your JS-file. You can either use // the .js-suffix or the alternative // .mjs-suffix, which allows the global // usage of 'await' when used with 'zx'. // The nessary shebang, as in Bash-scripts #!/usr/bin/env zx // A simple demonstration on how to // call Bash-command inside your JS. // Here, we log the current working directory. await $`echo $PWD`;
// Now to call your file, you can // simply use 'npx', the node package // executor that comes with NPM. npx zx ./demo.mjs // For more examples, check out the // repo where Google provides some // more real-world use cases.
By using the dollar-sign as an operator followed by two backticks that include you Bash-code, you can make actual calls as in a Bash-script.
More to explore
This article only aims at giving an introduction into the package. For more information, check out the links in the addendum to fully explore the API and all the features “zx” supports.