Building your own Command Line Interface (CLI) is easier than you might think with Node.js. There are a bunch of open-source packages that can handle colors, animation, and user input with ease. Use them to build a CLI game from scratch using only JavaScript. 

To play my CLI game, run "npx firequiz" from your terminal. 

#javascript #programming #game

🔗 Resources

Chalk https://github.com/chalk/chalk
Inquirer https://github.com/SBoudrias/Inquirer.js/
Colors.js Controversy https://www.theverge.com/2022/1/9/22874949/developer-corrupts-open-source-libraries-projects-affected
Source Code https://github.com/fireship-io/javascript-millionaire

🔥 Get More Content - Upgrade to PRO

Upgrade to Fireship PRO at https://fireship.io/pro
Use code lORhwXd2 for 25% off your first payment. 

🎨 My Editor Settings

- Atom One Dark 
- vscode-icons
- Fira Code Font

🔖 Topics Covered

- Build a Command Line Interface Node.js
- Top 5 packages for Node.js command line
- Building a terminal game
- Bash vs Node.js
- How to deploy an NPX script
- How to use ESM modules
2024-02-04T13:45:40.972Z
nova-2
2-general-nova
2024-01-09.29447
30089e05-99d1-4376-b32e-c263170674af
367455d8-365f-4236-985a-154f20da0947
8a0eb7326cbcefa6a3ab734d9b8916fb0c5fa3c128f38ce6a2a99bd3ea2957a9
67875a7f-c9c4-48a0-aa55-5bdb8a91c34a
deprecated
The one thing that makes developers different than the common people out there is the command line.
The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker.
In today's video, we'll take things to the next level by building a crazy command line tool from scratch.
In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal.
That's because I deployed it to npm as an executable, and I'll show you how you can too.
Now I realize that people will bash me for not using bash in this video, but the Node.
Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard.
If you're new here, like and subscribe.
Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie.
Let's first take a look at what we're building today.
We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire.
Then it will prompt you to enter your name.
After that, it goes through a series of multiple choice questions.
When you enter an answer, it will show a loading spinner.
If you get it right, it will continue.
J but if you get it wrong, it will exit the command line script and call you a loser.
If you make it all the way to the end, you win.
It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie.
To get started with this tutorial, create an empty directory.
Now go ahead and open that directory in Versus Code, bin run npm init flag y.
That will create a new package JSON file where we can install node dependencies.
Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code.
Inside the package JSON, we'll wanna change the type to module.
Doing that tells Node.
Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function.
Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top.
You'll always Glunt to include one of these when writing a command line script for somebody else to use.
It tells the operating system to execute the code with the Node.
Js version installed on the user's local system.
From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard.
Its purpose is very simple.
It will color the output text in the terminal.
There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs.
Bugs so strange that they got put on the news, so you might wanna be careful with that one.
Chalk has a bunch of built in colors.
And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color.
At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text.
Colored text is cool, but what's even better is animated colored text.
A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well.
In the code here, I'm creating a global variable for the player name then an async function called welcome.
The welcome screen will animate the text who wants to be a JavaScript millionaire.
Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user.
To handle that I'm creating a helper function here called sleep.
It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout.
You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout.
In any case, we can now call await sleep inside of our function.
That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game.
You'll notice I'm using backticks when console logging, which creates a JavaScript template literal.
A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters.
Now let's go ahead and call our function, g, but let's also include the await keyword in front of it.
That may seem strange because we're using await outside of an async function.
That's possible because Node.
Js supports top level await.
J.
In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable.
Go ahead and run the script, and you should now get that cool rainbow animation.
Now we're going to take a look at another very popular library used in many command line tools just called enquirer.
Its job is to collect user input and has a variety of different ways for doing so.
To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options.
You'll first give the data a name, and then the type specifies how that information should be collected.
An input is like a form that the user can type into.
GPU.
You can also do things like validate the input or provide a default value as we're doing here.
Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable.
Now go ahead and run that function with top level await and the command line should prompt you for some input.
Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz.
This function will work in almost the exact same way.
The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from.
Now we'll need to handle the UI differently based on whether or not the user selects the correct option.
For that, I'm creating another function gen called handle answer that takes a boolean as its argument.
Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer.
If the answer is correct, then we can say spinner success and move on to the next question.
Otherwise, device.
We're going to say spinner error, and then call process exit with an argument of 1.
When a process exits, it usually has a code of 0 or 1.
One means that it exited with errors.
0 means everything was fine, and what it will do is just kill the script right away.
Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x.
Now all the other questions are implemented in the exact same way.
So now let's implement the screen for the winner.
The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000.
We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language.
J.
What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius.
On top of that, let's make it look even more spectacular using the gradient string package.
It's kind of like chalk, but instead of a plain color, it creates a color gradient.
And now we can await each step in the process or a complete command line tool.
It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity.
I do it all the time for personal projects and for clients.
Now the final thing I want to show you is how to share it with the world via npx.
It's actually really easy.
All you have to do is go into the package.
Json and add an entry for bin dot points to your index JS file.
From there, run npm login.
You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud.
Congratulations, you just deployed a beautiful command line interface.
Thanks for watching and I will see you in the next one.

Speaker 0: The one thing that makes developers different than the common people out there is the command line. The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker. In today's video, we'll take things to the next level by building a crazy command line tool from scratch. In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal. That's because I deployed it to npm as an executable, and I'll show you how you can too.

Now I realize that people will bash me for not using bash in this video, but the Node. Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard. If you're new here, like and subscribe. Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie. Let's first take a look at what we're building today.

We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire. Then it will prompt you to enter your name. After that, it goes through a series of multiple choice questions. When you enter an answer, it will show a loading spinner. If you get it right, it will continue.

J but if you get it wrong, it will exit the command line script and call you a loser. If you make it all the way to the end, you win. It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie. To get started with this tutorial, create an empty directory. Now go ahead and open that directory in Versus Code, bin run npm init flag y.

That will create a new package JSON file where we can install node dependencies. Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code. Inside the package JSON, we'll wanna change the type to module. Doing that tells Node. Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function.

Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top. You'll always Glunt to include one of these when writing a command line script for somebody else to use. It tells the operating system to execute the code with the Node. Js version installed on the user's local system. From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard.

Its purpose is very simple. It will color the output text in the terminal. There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs. Bugs so strange that they got put on the news, so you might wanna be careful with that one. Chalk has a bunch of built in colors.

And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color. At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text. Colored text is cool, but what's even better is animated colored text. A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well. In the code here, I'm creating a global variable for the player name then an async function called welcome.

The welcome screen will animate the text who wants to be a JavaScript millionaire. Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user. To handle that I'm creating a helper function here called sleep. It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout. You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout.

In any case, we can now call await sleep inside of our function. That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game. You'll notice I'm using backticks when console logging, which creates a JavaScript template literal. A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters. Now let's go ahead and call our function, g, but let's also include the await keyword in front of it.

That may seem strange because we're using await outside of an async function. That's possible because Node. Js supports top level await. J. In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable.

Go ahead and run the script, and you should now get that cool rainbow animation. Now we're going to take a look at another very popular library used in many command line tools just called enquirer. Its job is to collect user input and has a variety of different ways for doing so. To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options. You'll first give the data a name, and then the type specifies how that information should be collected.

An input is like a form that the user can type into. GPU. You can also do things like validate the input or provide a default value as we're doing here. Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable. Now go ahead and run that function with top level await and the command line should prompt you for some input.

Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz. This function will work in almost the exact same way. The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from. Now we'll need to handle the UI differently based on whether or not the user selects the correct option. For that, I'm creating another function gen called handle answer that takes a boolean as its argument.

Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer. If the answer is correct, then we can say spinner success and move on to the next question. Otherwise, device. We're going to say spinner error, and then call process exit with an argument of 1. When a process exits, it usually has a code of 0 or 1.

One means that it exited with errors. 0 means everything was fine, and what it will do is just kill the script right away. Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x. Now all the other questions are implemented in the exact same way. So now let's implement the screen for the winner.

The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000. We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language. J. What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius. On top of that, let's make it look even more spectacular using the gradient string package.

It's kind of like chalk, but instead of a plain color, it creates a color gradient. And now we can await each step in the process or a complete command line tool. It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity. I do it all the time for personal projects and for clients. Now the final thing I want to show you is how to share it with the world via npx.

It's actually really easy. All you have to do is go into the package. Json and add an entry for bin dot points to your index JS file. From there, run npm login. You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud.

Congratulations, you just deployed a beautiful command line interface. Thanks for watching and I will see you in the next one.
The one thing that makes developers different than the common people out there is the command line. The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker. In today's video, we'll take things to the next level by building a crazy command line tool from scratch. In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal. That's because I deployed it to npm as an executable, and I'll show you how you can too.
software
software development
Now I realize that people will bash me for not using bash in this video, but the Node. Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard. If you're new here, like and subscribe. Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie. Let's first take a look at what we're building today. We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire. Then it will prompt you to enter your name. After that, it goes through a series of multiple choice questions. When you enter an answer, it will show a loading spinner. If you get it right, it will continue. J but if you get it wrong, it will exit the command line script and call you a loser.
If you make it all the way to the end, you win. It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie. To get started with this tutorial, create an empty directory.
youtube
Now go ahead and open that directory in Versus Code, bin run npm init flag y. That will create a new package JSON file where we can install node dependencies. Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code. Inside the package JSON, we'll wanna change the type to module. Doing that tells Node. Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function.
Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top. You'll always Glunt to include one of these when writing a command line script for somebody else to use. It tells the operating system to execute the code with the Node. Js version installed on the user's local system. From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard. Its purpose is very simple.
programming
software
software development
It will color the output text in the terminal. There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs.
Bugs so strange that they got put on the news, so you might wanna be careful with that one. Chalk has a bunch of built in colors. And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color.
bugs
At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text. Colored text is cool, but what's even better is animated colored text. A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well. In the code here, I'm creating a global variable for the player name then an async function called welcome.
animation
The welcome screen will animate the text who wants to be a JavaScript millionaire. Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user. To handle that I'm creating a helper function here called sleep. It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout.
You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout. In any case, we can now call await sleep inside of our function. That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game. You'll notice I'm using backticks when console logging, which creates a JavaScript template literal. A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters.
animation
Now let's go ahead and call our function, g, but let's also include the await keyword in front of it. That may seem strange because we're using await outside of an async function. That's possible because Node. Js supports top level await. J. In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable.
Go ahead and run the script, and you should now get that cool rainbow animation. Now we're going to take a look at another very popular library used in many command line tools just called enquirer. Its job is to collect user input and has a variety of different ways for doing so.
animation
software
youtube
disney
To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options. You'll first give the data a name, and then the type specifies how that information should be collected. An input is like a form that the user can type into. GPU. You can also do things like validate the input or provide a default value as we're doing here. Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable. Now go ahead and run that function with top level await and the command line should prompt you for some input. Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz.
This function will work in almost the exact same way. The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from. Now we'll need to handle the UI differently based on whether or not the user selects the correct option. For that, I'm creating another function gen called handle answer that takes a boolean as its argument. Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer.
programming
If the answer is correct, then we can say spinner success and move on to the next question. Otherwise, device. We're going to say spinner error, and then call process exit with an argument of 1. When a process exits, it usually has a code of 0 or 1. One means that it exited with errors. 0 means everything was fine, and what it will do is just kill the script right away. Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x.
Now all the other questions are implemented in the exact same way. So now let's implement the screen for the winner. The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000. We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language. J. What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius. On top of that, let's make it look even more spectacular using the gradient string package.
programming
graphic design
visualization
It's kind of like chalk, but instead of a plain color, it creates a color gradient.
And now we can await each step in the process or a complete command line tool. It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity. I do it all the time for personal projects and for clients. Now the final thing I want to show you is how to share it with the world via npx.
software development
software
It's actually really easy. All you have to do is go into the package. Json and add an entry for bin dot points to your index JS file. From there, run npm login. You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud.
Congratulations, you just deployed a beautiful command line interface. Thanks for watching and I will see you in the next one.
The one thing that makes developers different than the common people out there is the command line. The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker. In today's video, we'll take things to the next level by building a crazy command line tool from scratch. In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal. That's because I deployed it to npm as an executable, and I'll show you how you can too. Now I realize that people will bash me for not using bash in this video, but the Node. Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard. If you're new here, like and subscribe. Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie. Let's first take a look at what we're building today. We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire. Then it will prompt you to enter your name. After that, it goes through a series of multiple choice questions. When you enter an answer, it will show a loading spinner. If you get it right, it will continue. J but if you get it wrong, it will exit the command line script and call you a loser. If you make it all the way to the end, you win. It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie. To get started with this tutorial, create an empty directory. Now go ahead and open that directory in Versus Code, bin run npm init flag y. That will create a new package JSON file where we can install node dependencies. Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code. Inside the package JSON, we'll wanna change the type to module. Doing that tells Node. Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function. Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top. You'll always Glunt to include one of these when writing a command line script for somebody else to use. It tells the operating system to execute the code with the Node. Js version installed on the user's local system. From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard. Its purpose is very simple. It will color the output text in the terminal. There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs. Bugs so strange that they got put on the news, so you might wanna be careful with that one. Chalk has a bunch of built in colors. And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color. At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text. Colored text is cool, but what's even better is animated colored text. A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well. In the code here, I'm creating a global variable for the player name then an async function called welcome. The welcome screen will animate the text who wants to be a JavaScript millionaire. Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user. To handle that I'm creating a helper function here called sleep. It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout. You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout. In any case, we can now call await sleep inside of our function. That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game. You'll notice I'm using backticks when console logging, which creates a JavaScript template literal. A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters. Now let's go ahead and call our function, g, but let's also include the await keyword in front of it. That may seem strange because we're using await outside of an async function. That's possible because Node. Js supports top level await. J. In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable. Go ahead and run the script, and you should now get that cool rainbow animation. Now we're going to take a look at another very popular library used in many command line tools just called enquirer. Its job is to collect user input and has a variety of different ways for doing so. To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options. You'll first give the data a name, and then the type specifies how that information should be collected. An input is like a form that the user can type into. GPU. You can also do things like validate the input or provide a default value as we're doing here. Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable. Now go ahead and run that function with top level await and the command line should prompt you for some input. Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz. This function will work in almost the exact same way. The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from. Now we'll need to handle the UI differently based on whether or not the user selects the correct option. For that, I'm creating another function gen called handle answer that takes a boolean as its argument. Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer. If the answer is correct, then we can say spinner success and move on to the next question. Otherwise, device. We're going to say spinner error, and then call process exit with an argument of 1. When a process exits, it usually has a code of 0 or 1. One means that it exited with errors. 0 means everything was fine, and what it will do is just kill the script right away. Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x. Now all the other questions are implemented in the exact same way. So now let's implement the screen for the winner. The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000. We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language. J. What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius. On top of that, let's make it look even more spectacular using the gradient string package. It's kind of like chalk, but instead of a plain color, it creates a color gradient. And now we can await each step in the process or a complete command line tool. It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity. I do it all the time for personal projects and for clients. Now the final thing I want to show you is how to share it with the world via npx. It's actually really easy. All you have to do is go into the package. Json and add an entry for bin dot points to your index JS file. From there, run npm login. You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud. Congratulations, you just deployed a beautiful command line interface. Thanks for watching and I will see you in the next one.
The
the
one
one
thing
thing
that
that
makes
makes
developers
developers
different
different
than
than
the
the
common
common
people
people
out
out
there
there
is
is
the
the
command
command
line.
line
The
the
moment
moment
someone
someone
opens
opens
up
up
a
a
terminal
terminal
and
and
types
types
out
out
their
their
first
first
command,
command
they're
they're
instantly
instantly
transformed
transformed
into
into
a
a
Jedi
jedi
hacker.
hacker
In
in
today's
today's
video,
video
we'll
we'll
take
take
things
things
to
to
the
the
next
next
level
level
by
by
building
building
a
a
crazy
crazy
command
command
line
line
tool
tool
from
from
scratch.
scratch
In
in
fact,
fact
you
you
can
can
try
try
out
out
the
the
app
app
we're
we're
building
building
right
right
now
now
by
by
running
running
npx
npx
fire
fire
jerk
jerk
quiz
quiz
from
from
your
your
terminal.
terminal
That's
that's
because
because
I
i
deployed
deployed
it
it
to
to
npm
npm
as
as
an
an
executable,
executable
and
and
I'll
i'll
show
show
you
you
how
how
you
you
can
can
too.
too
Now
now
I
i
realize
realize
that
that
people
people
will
will
bash
bash
me
me
for
for
not
not
using
using
bash
bash
in
in
this
this
video,
video
but
but
the
the
Node.
node
Js
js
ecosystem
ecosystem
has
has
all
all
kinds
kinds
of
of
awesome
awesome
tools
tools
that
that
can
can
help
help
you
you
build
build
an
an
over
over
the
the
top
top
command
command
line
line
tool
tool
that'll
that'll
make
make
people
people
think
think
you're
you're
some
some
kind
kind
of
of
coding
coding
wizard.
wizard
If
if
you're
you're
new
new
here,
here
like
like
and
and
subscribe.
subscribe
Then
then
the
the
first
first
person
person
to
to
win
win
the
the
game
game
of
of
who
who
wants
wants
to
to
be
be
a
a
JavaScript
javascript
millionaire,
millionaire
gets
gets
a
a
free
free
Fireship
fireship
hoodie.
hoodie
Let's
let's
first
first
take
take
a
a
look
look
at
at
what
what
we're
we're
building
building
today.
today
We
we
have
have
a
a
command
command
line
line
tool
tool
that
that
animates
animates
the
the
text,
text
who
who
wants
wants
to
to
be
be
a
a
JavaScript
javascript
Germaniaire.
germaniaire
Then
then
it
it
will
will
prompt
prompt
you
you
to
to
enter
enter
your
your
name.
name
After
after
that,
that
it
it
goes
goes
through
through
a
a
series
series
of
of
multiple
multiple
choice
choice
questions.
questions
When
when
you
you
enter
enter
an
an
answer,
answer
it
it
will
will
show
show
a
a
loading
loading
spinner.
spinner
If
if
you
you
get
get
it
it
right,
right
it
it
will
will
continue.
continue
J
j
but
but
if
if
you
you
get
get
it
it
wrong,
wrong
it
it
will
will
exit
exit
the
the
command
command
line
line
script
script
and
and
call
call
you
you
a
a
loser.
loser
If
if
you
you
make
make
it
it
all
all
the
the
way
way
to
to
the
the
end,
end
you
you
win.
win
It
it
will
will
show
show
you
you
some
some
ASCII
ascii
text
text
with
with
a
a
color
color
gradient
gradient
and
and
a
a
message
message
that
that
when
when
left
left
in
in
the
the
comments
comments
on
on
this
this
YouTube
youtube
video,
video
wins
wins
you
you
a
a
free
free
hoodie.
hoodie
To
to
get
get
started
started
with
with
this
this
tutorial,
tutorial
create
create
an
an
empty
empty
directory.
directory
Now
now
go
go
ahead
ahead
and
and
open
open
that
that
directory
directory
in
in
Versus
versus
Code,
code
bin
bin
run
run
npm
npm
init
init
flag
flag
y.
y
That
that
will
will
create
create
a
a
new
new
package
package
JSON
json
file
file
where
where
we
we
can
can
install
install
node
node
dependencies.
dependencies
Now
now
I
i
have
have
a
a
list
list
of
of
packages
packages
to
to
install
install
here
here
and
and
I'll
i'll
explain
explain
what
what
each
each
one
one
does
does
as
as
we
we
JIT
jit
into
into
the
the
code.
code
Inside
inside
the
the
package
package
JSON,
json
we'll
we'll
wanna
wanna
change
change
the
the
type
type
to
to
module.
module
Doing
doing
that
that
tells
tells
Node.
node
Js
js
that
that
we
we
wanna
wanna
use
use
e
e
s
s
m
m
modules,
modules
allowing
allowing
us
us
to
to
use
use
the
the
import
import
export
export
syntax
syntax
instead
instead
of
of
the
the
common
common
JS
js
require
require
function.
function
Now,
now
let's
let's
create
create
an
an
index
index
dot
dot
JS
js
file
file
for
for
the
the
source
source
code,
code
and
and
inside
inside
of
of
it,
it
the
the
first
first
thing
thing
we'll
we'll
do
do
is
is
add
add
a
a
shebang
shebang
at
at
the
the
top.
top
You'll
you'll
always
always
Glunt
glunt
to
to
include
include
one
one
of
of
these
these
when
when
writing
writing
a
a
command
command
line
line
script
script
for
for
somebody
somebody
else
else
to
to
use.
use
It
it
tells
tells
the
the
operating
operating
system
system
to
to
execute
execute
the
the
code
code
with
with
the
the
Node.
node
Js
js
version
version
installed
installed
on
on
the
the
user's
user's
local
local
system.
system
From
from
import
import
in
in
all
all
of
of
our
our
dependencies,
dependencies
and
and
the
the
first
first
one
one
that
that
I
i
wanna
wanna
show
show
you
you
how
how
to
to
use
use
is
is
Chalk,
chalk
which
which
is
is
created
created
by
by
one
one
of
of
the
the
most
most
prolific
prolific
open
open
source
source
creators
creators
out
out
there,
there
Syndrasaurus,
syndrasaurus
just
just
an
an
actual
actual
code
code
wizard.
wizard
Its
its
purpose
purpose
is
is
very
very
simple.
simple
It
it
will
will
color
color
the
the
output
output
text
text
in
in
the
the
terminal.
terminal
There's
there's
also
also
a
a
popular
popular
alternative
alternative
called
called
colorsjs,
colorsjs
but
but
its
its
most
most
recent
recent
version
version
is
is
known
known
to
to
have
have
some
some
pretty
pretty
strange
strange
bugs.
bugs
Bugs
bugs
so
so
strange
strange
that
that
they
they
got
got
put
put
on
on
the
the
news,
news
so
so
you
you
might
might
wanna
wanna
be
be
careful
careful
with
with
that
that
one.
one
Chalk
chalk
has
has
a
a
bunch
bunch
of
of
built
built
in
in
colors.
colors
And
and
to
to
change
change
the
the
color
color
of
of
some
some
text,
text
all
all
you
you
have
have
to
to
do
do
is
is
wrap
wrap
it
it
in
in
the
the
color
color
that
that
you
you
want
want
or
or
you
you
might
might
use
use
a
a
background
background
color.
color
At
at
this
this
point,
point
let's
let's
test
test
job
job
by
by
opening
opening
the
the
terminal
terminal
and
and
running
running
node
node
index
index
dotjs
dotjs
or
or
just
just
node
node
period
period
and
and
the
the
result
result
should
should
be
be
the
the
highlighted
highlighted
text.
text
Colored
colored
text
text
is
is
cool,
cool
but
but
what's
what's
even
even
better
better
is
is
animated
animated
colored
colored
text.
text
A
a
package
package
that
that
builds
builds
on
on
top
top
of
of
chalk
chalk
called
called
chalk
chalk
animation
animation
allows
allows
us
us
to
to
easily
easily
create
create
a
a
rainbow
rainbow
animation
animation
and
and
a
a
bunch
bunch
of
of
others
others
Aegis
aegis
as
as
well.
well
In
in
the
the
code
code
here,
here
I'm
i'm
creating
creating
a
a
global
global
variable
variable
for
for
the
the
player
player
name
name
then
then
an
an
async
async
function
function
called
called
welcome.
welcome
The
the
welcome
welcome
screen
screen
will
will
animate
animate
the
the
text
text
who
who
wants
wants
to
to
be
be
a
a
JavaScript
javascript
millionaire.
millionaire
Now
now
in
in
the
the
terminal,
terminal
we
we
can
can
only
only
do
do
one
one
thing
thing
at
at
a
a
time,
time
and
and
to
to
display
display
an
an
animation,
animation
we'll
we'll
need
need
a
a
couple
couple
of
of
seconds
seconds
to
to
show
show
it
it
to
to
the
the
user.
user
To
to
handle
handle
that
that
I'm
i'm
creating
creating
a
a
helper
helper
function
function
here
here
called
called
sleep.
sleep
It
it
takes
takes
an
an
argument
argument
of
of
milliseconds
milliseconds
that
that
defaults
defaults
to
to
2,000
2,000
and
and
then
then
resolves
resolves
a
a
promise
promise
with
with
a
a
set
set
timeout.
timeout
You'll
you'll
see
see
this
this
code
code
in
in
many
many
JavaScript
javascript
code
code
bases
bases
because
because
for
for
whatever
whatever
reason,
reason
JavaScript
javascript
doesn't
doesn't
implement
implement
a
a
promise
promise
based
based
timeout.
timeout
In
in
any
any
case,
case
we
we
can
can
now
now
call
call
await
await
sleep
sleep
inside
inside
of
of
our
our
function.
function
That
that
allows
allows
the
the
rainbow
rainbow
to
to
animate
animate
for
for
2
2
seconds
seconds
and
and
then
then
we'll
we'll
call
call
stop
stop
to
to
move
move
on
on
to
to
the
the
next
next
step
step
where
where
we
we
console
console
log
log
the
the
actual
actual
instructions
instructions
for
for
the
the
game.
game
You'll
you'll
notice
notice
I'm
i'm
using
using
backticks
backticks
when
when
console
console
logging,
logging
which
which
creates
creates
a
a
JavaScript
javascript
template
template
literal.
literal
A
a
template
template
literal
literal
allows
allows
us
us
to
to
interpolate
interpolate
values
values
into
into
the
the
text
text
and
and
also
also
create
create
multi
multi
line
line
logs
logs
without
without
manually
manually
including
including
line
line
break
break
characters.
characters
Now
now
let's
let's
go
go
ahead
ahead
and
and
call
call
our
our
function,
function
g,
g
but
but
let's
let's
also
also
include
include
the
the
await
await
keyword
keyword
in
in
front
front
of
of
it.
it
That
that
may
may
seem
seem
strange
strange
because
because
we're
we're
using
using
await
await
outside
outside
of
of
an
an
async
async
function.
function
That's
that's
possible
possible
because
because
Node.
node
Js
js
supports
supports
top
top
level
level
await.
await
J.
j
In
in
fact,
fact
we
we
could
could
probably
probably
write
write
this
this
entire
entire
app
app
without
without
defining
defining
a
a
single
single
function
function
and
and
just
just
use
use
top
top
level
level
await
await
for
for
everything,
everything
but
but
I
i
do
do
think
think
named
named
functions
functions
makes
makes
the
the
code
code
more
more
readable.
readable
Go
go
ahead
ahead
and
and
run
run
the
the
script,
script
and
and
you
you
should
should
now
now
get
get
that
that
cool
cool
rainbow
rainbow
animation.
animation
Now
now
we're
we're
going
going
to
to
take
take
a
a
look
look
at
at
another
another
very
very
popular
popular
library
library
used
used
in
in
many
many
command
command
line
line
tools
tools
just
just
called
called
enquirer.
enquirer
Its
its
job
job
is
is
to
to
collect
collect
user
user
input
input
and
and
has
has
a
a
variety
variety
of
of
different
different
ways
ways
for
for
doing
doing
so.
so
To
to
collect
collect
the
the
user's
user's
name,
name
we'll
we'll
first
first
create
create
an
an
enquirer
enquirer
prompt,
prompt
which
which
can
can
be
be
customized
customized
with
with
a
a
variety
variety
of
of
different
different
options.
options
You'll
you'll
first
first
give
give
the
the
data
data
a
a
name,
name
and
and
then
then
the
the
type
type
specifies
specifies
how
how
that
that
information
information
should
should
be
be
collected.
collected
An
an
input
input
is
is
like
like
a
a
form
form
that
that
the
the
user
user
can
can
type
type
into.
into
GPU.
gpu
You
you
can
can
also
also
do
do
things
things
like
like
validate
validate
the
the
input
input
or
or
provide
provide
a
a
default
default
value
value
as
as
we're
we're
doing
doing
here.
here
Now
now
when
when
the
the
promise
promise
resolves,
resolves
it
it
will
will
return
return
the
the
player's
player's
name,
name
which
which
is
is
assigned
assigned
to
to
the
the
global
global
player
player
name
name
variable.
variable
Now
now
go
go
ahead
ahead
and
and
run
run
that
that
function
function
with
with
top
top
level
level
await
await
and
and
the
the
command
command
line
line
should
should
prompt
prompt
you
you
for
for
some
some
input.
input
Now
now
the
the
next
next
thing
thing
we'll
we'll
do
do
is
is
use
use
inquirer
inquirer
jar
jar
to
to
create
create
multiple
multiple
choice
choice
questions
questions
for
for
the
the
quiz.
quiz
This
this
function
function
will
will
work
work
in
in
almost
almost
the
the
exact
exact
same
same
way.
way
The
the
only
only
difference
difference
is
is
that
that
instead
instead
of
of
an
an
input,
input
we're
we're
now
now
using
using
a
a
list,
list
which
which
has
has
multiple
multiple
choices
choices
to
to
choose
choose
from.
from
Now
now
we'll
we'll
need
need
to
to
handle
handle
the
the
UI
ui
differently
differently
based
based
on
on
whether
whether
or
or
not
not
the
the
user
user
selects
selects
the
the
correct
correct
option.
option
For
for
that,
that
I'm
i'm
creating
creating
another
another
function
function
gen
gen
called
called
handle
handle
answer
answer
that
that
takes
takes
a
a
boolean
boolean
as
as
its
its
argument.
argument
Inside
inside
the
the
function,
function
we'll
we'll
create
create
a
a
loading
loading
spinner
spinner
with
with
a
a
package
package
called
called
nano
nano
spinner
spinner
that
that
will
will
run
run
for
for
2
2
seconds
seconds
while
while
checking
checking
the
the
answer.
answer
If
if
the
the
answer
answer
is
is
correct,
correct
then
then
we
we
can
can
say
say
spinner
spinner
success
success
and
and
move
move
on
on
to
to
the
the
next
next
question.
question
Otherwise,
otherwise
device.
device
We're
we're
going
going
to
to
say
say
spinner
spinner
error,
error
and
and
then
then
call
call
process
process
exit
exit
with
with
an
an
argument
argument
of
of
1.
1
When
when
a
a
process
process
exits,
exits
it
it
usually
usually
has
has
a
a
code
code
of
of
0
0
or
or
1.
1
One
one
means
means
that
that
it
it
exited
exited
with
with
errors.
errors
0
0
means
means
everything
everything
was
was
fine,
fine
and
and
what
what
it
it
will
will
do
do
is
is
just
just
kill
kill
the
the
script
script
right
right
away.
away
Let's
let's
go
go
ahead
ahead
and
and
run
run
that
that
function
function
and
and
you
you
JIT
jit
get
get
a
a
multiple
multiple
choice
choice
question
question
that
that
when
when
answered
answered
correctly
correctly
will
will
give
give
you
you
a
a
green
green
check
check
mark
mark
and
and
when
when
answered
answered
incorrectly
incorrectly
will
will
give
give
you
you
a
a
red
red
x.
x
Now
now
all
all
the
the
other
other
questions
questions
are
are
implemented
implemented
in
in
the
the
exact
exact
same
same
way.
way
So
so
now
now
let's
let's
implement
implement
the
the
screen
screen
for
for
the
the
winner.
winner
The
the
function
function
will
will
clear
clear
the
the
console's
console's
current
current
output
output
and
and
then
then
format
format
a
a
message
message
called
called
congrats
congrats
player
player
name,
name
here's
here's
a
a
$1,000,000.
$1,000,000
We'll
we'll
then
then
pass
pass
the
the
message
message
on
on
to
to
Figlet,
figlet
which
which
is
is
actually
actually
a
a
JavaScript
javascript
implementation
implementation
of
of
a
a
popular
popular
program
program
implemented
implemented
in
in
the
the
c
c
language.
language
J.
j
What
what
it
it
does
does
is
is
generate
generate
ASCII
ascii
art
art
from
from
text,
text
which
which
is
is
really
really
useful
useful
for
for
making
making
your
your
non
non
programmer
programmer
friends
friends
think
think
you're
you're
some
some
kind
kind
of
of
genius.
genius
On
on
top
top
of
of
that,
that
let's
let's
make
make
it
it
look
look
even
even
more
more
spectacular
spectacular
using
using
the
the
gradient
gradient
string
string
package.
package
It's
it's
kind
kind
of
of
like
like
chalk,
chalk
but
but
instead
instead
of
of
a
a
plain
plain
color,
color
it
it
creates
creates
a
a
color
color
gradient.
gradient
And
and
now
now
we
we
can
can
await
await
each
each
step
step
in
in
the
the
process
process
or
or
a
a
complete
complete
command
command
line
line
tool.
tool
It
it
may
may
seem
seem
trivial,
trivial
but
but
knowing
knowing
how
how
to
to
build
build
your
your
own
own
CLI
cli
tool
tool
can
can
be
be
extremely
extremely
useful
useful
for
for
productivity.
productivity
I
i
do
do
it
it
all
all
the
the
time
time
for
for
personal
personal
projects
projects
and
and
for
for
clients.
clients
Now
now
the
the
final
final
thing
thing
I
i
want
want
to
to
show
show
you
you
is
is
how
how
to
to
share
share
it
it
with
with
the
the
world
world
via
via
npx.
npx
It's
it's
actually
actually
really
really
easy.
easy
All
all
you
you
have
have
to
to
do
do
is
is
go
go
into
into
the
the
package.
package
Json
json
and
and
add
add
an
an
entry
entry
for
for
bin
bin
dot
dot
points
points
to
to
your
your
index
index
JS
js
file.
file
From
from
there,
there
run
run
npm
npm
login.
login
You'll
you'll
need
need
to
to
have
have
an
an
npm
npm
account
account
where
where
you
you
can
can
publish
publish
all
all
your
your
useless
useless
packages,
packages
then
then
run
run
npm
npm
publish
publish
to
to
push
push
your
your
code
code
to
to
the
the
cloud.
cloud
Congratulations,
congratulations
you
you
just
just
deployed
deployed
a
a
beautiful
beautiful
command
command
line
line
interface.
interface
Thanks
thanks
for
for
watching
watching
and
and
I
i
will
will
see
see
you
you
in
in
the
the
next
next
one.
one
success
The speakers discuss a command line tool called Chalk, which allows developers to create a rainbow animation and other elements. They also show a tutorial on using Chalk in code to create a rainbow animation and other elements. The command line script is used to create an index file and use a file called Chalk, which allows for multiple choice quizzes and the command line interface to publish and push code to the cloud. A library called enquiring allows users to collect user input and create multiple choice questions for a quiz, and the command line tool is used to share a award and personal projects.
I created a Command Line Game for you // 5-Minute Node.js CLI Project
The one thing that makes developers different than the common people out there is the command line. The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker. In today's video, we'll take things to the next level by building a crazy command line tool from scratch. In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal. That's because I deployed it to npm as an executable, and I'll show you how you can too. Now I realize that people will bash me for not using bash in this video, but the Node. Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard. If you're new here, like and subscribe. Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie. Let's first take a look at what we're building today. We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire. Then it will prompt you to enter your name. After that, it goes through a series of multiple choice questions. When you enter an answer, it will show a loading spinner. If you get it right, it will continue. J but if you get it wrong, it will exit the command line script and call you a loser. If you make it all the way to the end, you win. It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie. To get started with this tutorial, create an empty directory. Now go ahead and open that directory in Versus Code, bin run npm init flag y. That will create a new package JSON file where we can install node dependencies. Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code. Inside the package JSON, we'll wanna change the type to module. Doing that tells Node. Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function. Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top. You'll always Glunt to include one of these when writing a command line script for somebody else to use. It tells the operating system to execute the code with the Node. Js version installed on the user's local system. From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard. Its purpose is very simple. It will color the output text in the terminal. There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs. Bugs so strange that they got put on the news, so you might wanna be careful with that one. Chalk has a bunch of built in colors. And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color. At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text. Colored text is cool, but what's even better is animated colored text. A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well. In the code here, I'm creating a global variable for the player name then an async function called welcome. The welcome screen will animate the text who wants to be a JavaScript millionaire. Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user. To handle that I'm creating a helper function here called sleep. It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout. You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout. In any case, we can now call await sleep inside of our function. That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game. You'll notice I'm using backticks when console logging, which creates a JavaScript template literal. A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters. Now let's go ahead and call our function, g, but let's also include the await keyword in front of it. That may seem strange because we're using await outside of an async function. That's possible because Node. Js supports top level await. J. In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable. Go ahead and run the script, and you should now get that cool rainbow animation. Now we're going to take a look at another very popular library used in many command line tools just called enquirer. Its job is to collect user input and has a variety of different ways for doing so. To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options. You'll first give the data a name, and then the type specifies how that information should be collected. An input is like a form that the user can type into. GPU. You can also do things like validate the input or provide a default value as we're doing here. Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable. Now go ahead and run that function with top level await and the command line should prompt you for some input. Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz. This function will work in almost the exact same way. The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from. Now we'll need to handle the UI differently based on whether or not the user selects the correct option. For that, I'm creating another function gen called handle answer that takes a boolean as its argument. Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer. If the answer is correct, then we can say spinner success and move on to the next question. Otherwise, device. We're going to say spinner error, and then call process exit with an argument of 1. When a process exits, it usually has a code of 0 or 1. One means that it exited with errors. 0 means everything was fine, and what it will do is just kill the script right away. Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x. Now all the other questions are implemented in the exact same way. So now let's implement the screen for the winner. The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000. We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language. J. What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius. On top of that, let's make it look even more spectacular using the gradient string package. It's kind of like chalk, but instead of a plain color, it creates a color gradient. And now we can await each step in the process or a complete command line tool. It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity. I do it all the time for personal projects and for clients. Now the final thing I want to show you is how to share it with the world via npx. It's actually really easy. All you have to do is go into the package. Json and add an entry for bin dot points to your index JS file. From there, run npm login. You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud. Congratulations, you just deployed a beautiful command line interface. Thanks for watching and I will see you in the next one.
The speakers discuss a command line tool called Chalk, which allows developers to create a rainbow animation and other elements. They also show a tutorial on using Chalk in code to create a rainbow animation and other elements. The command line script is used to create an index file and use a file called Chalk, which allows for multiple choice quizzes and the command line interface to publish and push code to the cloud. A library called enquiring allows users to collect user input and create multiple choice questions for a quiz, and the command line tool is used to share a award and personal projects.

        [INST]
        You are youtuber called Fireship you make engaging high-intensity and entertaining coding tutorials and tech news. 
        you covers a wide range of topics relevant to programmers, aiming to help them learn and improve their skills quickly.
        
        Given the title of the video : I created a Command Line Game for you // 5-Minute Node.js CLI Project 
        and a small summary : The speakers discuss a command line tool called Chalk, which allows developers to create a rainbow animation and other elements. They also show a tutorial on using Chalk in code to create a rainbow animation and other elements. The command line script is used to create an index file and use a file called Chalk, which allows for multiple choice quizzes and the command line interface to publish and push code to the cloud. A library called enquiring allows users to collect user input and create multiple choice questions for a quiz, and the command line tool is used to share a award and personal projects.
        [/INST]
        
        Generate the video : The one thing that makes developers different than the common people out there is the command line. The moment someone opens up a terminal and types out their first command, they're instantly transformed into a Jedi hacker. In today's video, we'll take things to the next level by building a crazy command line tool from scratch. In fact, you can try out the app we're building right now by running npx fire jerk quiz from your terminal. That's because I deployed it to npm as an executable, and I'll show you how you can too. Now I realize that people will bash me for not using bash in this video, but the Node. Js ecosystem has all kinds of awesome tools that can help you build an over the top command line tool that'll make people think you're some kind of coding wizard. If you're new here, like and subscribe. Then the first person to win the game of who wants to be a JavaScript millionaire, gets a free Fireship hoodie. Let's first take a look at what we're building today. We have a command line tool that animates the text, who wants to be a JavaScript Germaniaire. Then it will prompt you to enter your name. After that, it goes through a series of multiple choice questions. When you enter an answer, it will show a loading spinner. If you get it right, it will continue. J but if you get it wrong, it will exit the command line script and call you a loser. If you make it all the way to the end, you win. It will show you some ASCII text with a color gradient and a message that when left in the comments on this YouTube video, wins you a free hoodie. To get started with this tutorial, create an empty directory. Now go ahead and open that directory in Versus Code, bin run npm init flag y. That will create a new package JSON file where we can install node dependencies. Now I have a list of packages to install here and I'll explain what each one does as we JIT into the code. Inside the package JSON, we'll wanna change the type to module. Doing that tells Node. Js that we wanna use e s m modules, allowing us to use the import export syntax instead of the common JS require function. Now, let's create an index dot JS file for the source code, and inside of it, the first thing we'll do is add a shebang at the top. You'll always Glunt to include one of these when writing a command line script for somebody else to use. It tells the operating system to execute the code with the Node. Js version installed on the user's local system. From import in all of our dependencies, and the first one that I wanna show you how to use is Chalk, which is created by one of the most prolific open source creators out there, Syndrasaurus, just an actual code wizard. Its purpose is very simple. It will color the output text in the terminal. There's also a popular alternative called colorsjs, but its most recent version is known to have some pretty strange bugs. Bugs so strange that they got put on the news, so you might wanna be careful with that one. Chalk has a bunch of built in colors. And to change the color of some text, all you have to do is wrap it in the color that you want or you might use a background color. At this point, let's test job by opening the terminal and running node index dotjs or just node period and the result should be the highlighted text. Colored text is cool, but what's even better is animated colored text. A package that builds on top of chalk called chalk animation allows us to easily create a rainbow animation and a bunch of others Aegis as well. In the code here, I'm creating a global variable for the player name then an async function called welcome. The welcome screen will animate the text who wants to be a JavaScript millionaire. Now in the terminal, we can only do one thing at a time, and to display an animation, we'll need a couple of seconds to show it to the user. To handle that I'm creating a helper function here called sleep. It takes an argument of milliseconds that defaults to 2,000 and then resolves a promise with a set timeout. You'll see this code in many JavaScript code bases because for whatever reason, JavaScript doesn't implement a promise based timeout. In any case, we can now call await sleep inside of our function. That allows the rainbow to animate for 2 seconds and then we'll call stop to move on to the next step where we console log the actual instructions for the game. You'll notice I'm using backticks when console logging, which creates a JavaScript template literal. A template literal allows us to interpolate values into the text and also create multi line logs without manually including line break characters. Now let's go ahead and call our function, g, but let's also include the await keyword in front of it. That may seem strange because we're using await outside of an async function. That's possible because Node. Js supports top level await. J. In fact, we could probably write this entire app without defining a single function and just use top level await for everything, but I do think named functions makes the code more readable. Go ahead and run the script, and you should now get that cool rainbow animation. Now we're going to take a look at another very popular library used in many command line tools just called enquirer. Its job is to collect user input and has a variety of different ways for doing so. To collect the user's name, we'll first create an enquirer prompt, which can be customized with a variety of different options. You'll first give the data a name, and then the type specifies how that information should be collected. An input is like a form that the user can type into. GPU. You can also do things like validate the input or provide a default value as we're doing here. Now when the promise resolves, it will return the player's name, which is assigned to the global player name variable. Now go ahead and run that function with top level await and the command line should prompt you for some input. Now the next thing we'll do is use inquirer jar to create multiple choice questions for the quiz. This function will work in almost the exact same way. The only difference is that instead of an input, we're now using a list, which has multiple choices to choose from. Now we'll need to handle the UI differently based on whether or not the user selects the correct option. For that, I'm creating another function gen called handle answer that takes a boolean as its argument. Inside the function, we'll create a loading spinner with a package called nano spinner that will run for 2 seconds while checking the answer. If the answer is correct, then we can say spinner success and move on to the next question. Otherwise, device. We're going to say spinner error, and then call process exit with an argument of 1. When a process exits, it usually has a code of 0 or 1. One means that it exited with errors. 0 means everything was fine, and what it will do is just kill the script right away. Let's go ahead and run that function and you JIT get a multiple choice question that when answered correctly will give you a green check mark and when answered incorrectly will give you a red x. Now all the other questions are implemented in the exact same way. So now let's implement the screen for the winner. The function will clear the console's current output and then format a message called congrats player name, here's a $1,000,000. We'll then pass the message on to Figlet, which is actually a JavaScript implementation of a popular program implemented in the c language. J. What it does is generate ASCII art from text, which is really useful for making your non programmer friends think you're some kind of genius. On top of that, let's make it look even more spectacular using the gradient string package. It's kind of like chalk, but instead of a plain color, it creates a color gradient. And now we can await each step in the process or a complete command line tool. It may seem trivial, but knowing how to build your own CLI tool can be extremely useful for productivity. I do it all the time for personal projects and for clients. Now the final thing I want to show you is how to share it with the world via npx. It's actually really easy. All you have to do is go into the package. Json and add an entry for bin dot points to your index JS file. From there, run npm login. You'll need to have an npm account where you can publish all your useless packages, then run npm publish to push your code to the cloud. Congratulations, you just deployed a beautiful command line interface. Thanks for watching and I will see you in the next one.
        