Assess and Choose a 3rd Party Library for your Node.js CLI Tool

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

You want to focus your development efforts on the actual business logic of the application, not procedural aspects of the code like parsing inputs.

This is why we'll look for a 3rd party tool to parse user input. We'll look at 4 different libraries and walk through how to decide which will be best for this specific project.

Kevin Cunningham: [0:00] The Node philosophy follows the Unix philosophy, in that it says that everything should be small and do its job well. If I'm running a quizme app, and I'm writing a lot of parsing code, that's not my core business logic. I should be looking elsewhere for that parsing code. [0:17] There are lots of libraries available. There's one that's going to be in Node core called parseArgs, which we'll look at slightly separately, but I also want to handle question and answers. I want to ask the user a question, and I want to be able to get their answer and to do something with it.

[0:32] There are four different libraries I might think about for this to have a look at. This is Inquirer.js. Looking through, I can see it has quite a lot of weekly downloads, loads. I want to check, it's got 10 pull requests. It's got some issues. It was last published a month ago, so it's active, and it's popular. That suggests, to me, that this is a solid library to choose from.

[0:56] The next thing I'll have a look at is the installation, fine. Then, I have a look at what happens. We pass in the questions. Then, we get a prompt. We do something with it. Then, we catch any errors, fine. That looks sensible. There are types of questions. There is a name, a message, a default, some choices, lots of different things I could do.

[1:20] As I scroll down here, I'm thinking, "Does that seem to fit my project at the moment?" This does seem to fit my project, and it seems pretty intuitive. That's on the maybe list.

[1:30] Commander says it's a complete solution for new JS. Let's see how it works. Install it. We add in those parsing arguments, so we would handle that parsing piece. What about the question/answer piece? It's not jumping out at me how to do questions/answer style. I can leave that alone.

[1:50] Caporal. Is it a fully featured framework? The last one said it was too. It got colored output, custom loggers, typo suggestions. Those are very cool. Let's see if it's intuitive. We got some commands, some arguments, some options, and some actions and TypeScript for JavaScript and take [inaudible] commands. Now, do you do the question/answer?

[2:12] You got flags, fine. Do we have question and answer? Are we able to pose a question during the flow of the commands, not just at the start? This is beautiful for flags on the command line, but I also want to handle during the flow of the command. It doesn't look like it does, right? Again, this could mean me not understanding the program, I don't know.

[2:33] Yargs is going to be just for parsing arguments, taking ships = 12. OK, so we got lots of...parsing arguments.

[2:44] Having looked at four different possibilities, I'm back at this one I started with, Inquirer.js, which is going to allow me to pose questions and ask answers. When I think about my needs for parsing, they're minor enough that I can deal with my custom code. The question-and-answer piece, I think I want to use this library for.

[3:03] We're back at Inquirer.js. We're confident with downloads, we don't have that many dependencies. This is the one we're going to use.

egghead
egghead
~ 38 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today