Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

egghead.io

Get Started Building CLI Tools with Node.js

via egghead.io

Overview

As a developer, you have many tasks that you repeat on a day to day or project to project basis whether that’s setting up boilerplate, configuring projects just right, or… [insert your own joyless repetitive task here]. There's that saying about how if you do something more than twice you should automate it. You don’t have the time or energy to waste repeating actions when you can make robots do it for you, precisely the way you need it. But there’s a cost to automating any given task. You have to write and maintain code that will do your tasks for you. That means it’s incredibly difficult to leverage the knowledge you already have to add efficiency in your workflow. **And as a web developer**, you have the flexibility and ease of use of JavaScript through Node.js to command robots to take care of those pesky repeated tasks. Node.js has a huge ecosystem for you to leverage as well as a large API surface to handle a plethora of use cases. This makes Node.js versatile but if you’re just learning to script this can be overwhelming. When building a CLI there are a few common features that you’ll implement for most projects: - Parse user input through the CLI - Implement functionality based on flags - Read/Write data to a file - Execute your script globally in your system This course will introduce you to these core CLI features while using Node.js. In his course, Kevin walks you through building a `quizme` CLI from scratch. The CLI lets a user add questions and answer questions through the CLI. Through building this project, you’ll learn how to implement those common CLI features. [![node cli in action](https://res.cloudinary.com/dg3gyk0gu/image/upload/v1657579671/course-resources/get-started-building-cli-tools-with-node-js/node-cli-screenshot.png)](https://egghead.io/lessons/node-js-plan-a-node-js-cli-tool-project-with-readme-driven-development) By the end of the course, you will be understand what a productive developer workflow looks like when reading user input, displaying data in the CLI, persisting data in a file, and more!

Syllabus

  • Plan a Node.js CLI Tool Project with README Driven Development
  • Initialize a Node.js Project with NPM
  • Set the Node.js Project to ECMAScript Modules (ESM)
  • Parse User Input through Node.js process argv for Flags
  • Parse User Input in Node.js with readline
  • Assess and Choose a 3rd Party Library for your Node.js CLI Tool
  • Process User Input with Inquirer in Node.js
  • Assess and Choose Three Approaches to Reading from the File System in Node.js
  • Read a File with Node.js readFile from the File System and Parse Question and Answer
  • Log Question Results by using Node.js to Filter and Write to a File
  • Find a Random Element in a JSON File in Node.js
  • Add Question/Answer Object to our Data with Node.js writeFile
  • Offload Complex Logic and Confirm a Correct Answer with the User
  • Make a Node.js Script Globally Executable with a Shebang and a Symbolic Link
  • Handle Relative Paths in a Node.js ESM Project with import.meta.url
  • Use parseArgs to Parse your Command Line

Taught by

Kevin Cunningham

Reviews

4.6 rating at egghead.io based on 36 ratings

Start your review of Get Started Building CLI Tools with Node.js

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.