Fireship · @fireship
I created a Command Line Game for you // 5-Minute Node.js CLI Project
Uploaded January 27, 2022 · Length 6:25
Summary
Create a command line game using Node.js, including animation and user input, and deploy it via npm.
- node.js cli project
- command line game
- javascript game
- cli animation
- user input in cli
- npm deployment
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
the one thing that makes developers
- 0:01
different than the common people out
- 0:02
there is the command line the moment
- 0:04
someone opens up a terminal and types
- 0:06
out their first command they're
- 0:07
instantly transformed into a jedi hacker
- 0:09
in today's video we'll take things to
- 0:11
the next level by building a crazy
- 0:12
command line tool from scratch in fact
- 0:14
you can try out the app we're building
- 0:15
right now by running npx fire quiz from
- 0:18
your terminal that's because i deployed
- 0:19
it to npm as an executable and i'll show
- 0:21
you how you can too now i realize that
- 0:24
people will bash me for not using bash
- 0:25
in this video but the node.js ecosystem
- 0:28
has all kinds of awesome tools that can
- 0:29
help you build an over-the-top command
- 0:31
line tool that'll make people think
- 0:32
you're some kind of coding wizard if
- 0:34
you're new here like and subscribe then
- 0:35
the first person to win the game of who
- 0:36
wants to be a javascript millionaire
- 0:38
gets a free fire ship hoodie let's first
- 0:40
take a look at what we're building today
- 0:41
we have a command line tool that
- 0:42
animates the text who wants to be a
- 0:44
javascript millionaire then it will
- 0:45
prompt you to enter your name after that
- 0:48
it goes through a series of multiple
- 0:49
choice questions when you enter an
- 0:51
answer it will show a loading spinner if
- 0:52
you get it right it will continue but if
- 0:54
you get it wrong it will exit the
- 0:56
command line script and call you a loser
- 0:58
if you make it all the way to the end
- 0:59
you win it will show you some ascii text
- 1:01
with a color gradient and a message that
- 1:03
when left in the comments on this
- 1:04
youtube video wins you a free hoodie to
- 1:06
get started with this tutorial create an
- 1:08
empty directory now go ahead and open
- 1:09
that directory in vs code then run npm
- 1:12
init flag y that will create a new
- 1:13
package json file where we can install
- 1:15
node dependencies now i have a list of
- 1:17
packages to install here and i'll
- 1:19
explain what each one does as we get
- 1:20
into the code inside the package json
- 1:22
we'll want to change the type to module
- 1:24
doing that tells node.js that we want to
- 1:26
use esm modules allowing us to use the
- 1:28
import export syntax instead of the
- 1:30
commonjs require function now let's
- 1:32
create an index.js file for the source
- 1:34
code and inside of it the first thing
- 1:36
we'll do is add a shebang at the top
- 1:38
you'll always want to include one of
- 1:39
these when writing a command line script
- 1:40
for somebody else to use it tells the
- 1:42
operating system to execute the code
- 1:44
with the node.js version installed on
- 1:46
the user's local system from there i'm
- 1:47
importing all of our dependencies and
- 1:49
the first one that i want to show you
- 1:50
how to use is chalk which is created by
- 1:52
one of the most prolific open source
- 1:54
creators out there syndrasaurus an
- 1:56
actual codewizard its purpose is very
- 1:58
simple it will color the output text in


