Member-only story
Write Your First Shell Script With Node.js
Writing a shell script from scratch in Node.js
Shell scripts are very useful when working on a JavaScript app. If you’ve ever used create-react-app, that command essentially takes care of a lot of overhead needed when developing React apps.
Some of this overhead includes writing scripts you might use to execute or build your app, such as npm start
or npm run build
. These are great examples of commands that execute specific shell scripts.
After reading this, you will have successfully written a shell script from scratch in Node.js.
The script we are going to write is simple. Given the command npm run emoji
, the script will run and console.log
a random emoji in our terminal.
First things first, we need a file that will contain the code that the script will execute. Let’s call this file emoji.js
. Once the file is created, we can start writing the script itself.
If you’ve ever looked at your package.json
file (as a JavaScript developer it is imperative that you familiarize yourself with this file if you haven’t already), you’ve probably seen a section…