[Music]
hello everyone welcome back to mr random
generator
in this video i will be showing you a
module named chalk
so what is it well chalk is an npm
module
that enables us to colorize and stylize
our debugging statements
that we see in our console so why do we
need that
well imagine a situation where you want
to debug a project
and you put some console.log statements
here and there
so if you build that project the chances
are you will see
thousands of lines of debugging
statements into your
console so finding the specific ones
through your terminal is actually really
difficult thing to do so chalk is
really helpful too for us
developers to use it in order to solve
that issue basically
so how do we use that as you can see i
have a
visual studio code open right there with
an empty directory named chalk
so the first thing i want to do is
initialize our projects
like so then what we need to do is
install chalk
now it's installed what we can do is
create a javascript file and inside our
javascript file
we can import the chalk
like so
so using the chalk is actually really
simple
what you can do is use your ordinary
logging statements
and inside your login statements you can
specify the chalk
instances by giving by naming it chalk
dot let's say i want to make my message
green
green and inside that i can
put my statement let's say everything
was going fine until
so i want to make my until
world word underlined
and orange so as you can see if i type
orange
uh it says it says to me that the orange
is
not existing inside the chalk so what i
can do is i can
give the rgb values or i can give
the x values so let's stick with hex
and give an orange value of
let's say EE800
and after that i can specify the
underlining
feature by typing it underline
and then i can give my message which is
until
and after that i can also concatenate an
error message
as for our error message i want that to
be black
and it should have a
red background so first i mentioned the
foreground color which is black
let's type in black then inside that
i can give chalk.
Bg stands for background red and inside
that i can give my
error message which is
occurred so let's save it
and run it
as you can see it is working properly
obviously you can do much more stuff
than that
let's say i want to use a variable named
fps which is
144. so
using that is actually really simple
again we put console.log
and inside that we can type chalk
and put our two quotes and inside that
we can actually
type in fps to basically
not color the initial statement but
after that
so you will get what i want to say in
a minute
so we put fps there so after that
we can put let's say this and we specify
the color name
which is red and then i pass my variable
as usual like so
and if i run that what i will i should
see is
the white fps followed by a red 144
so let's test that out as you can see it
is working properly
one important thing to mention uh here
is that if you put a space between the
curly brace and red
it won't work as you can see we get an
error message
so you need to be careful while using
that
so i think now you'll get the basics so
now let's do something bit more
interesting shall we
so let's delete those and install a new
module
named log updates so npm install
log updates what that module enables us
to do is
we can update our
logging statements without actually
printing
another statement on top of it so
imagine a loading
bar type of situation so let's
import that in our project by
log update require
and let's mention yeah
just like that and after that
let's define an array
of output let's say output
that has chalk elements which are
plugging statements
of let's say
let's make it red of
buzz and
blue of his
the classical fizz buzz then
define a switch let's say make it 0
and after that open up an
interval and pass a basic function
inside that like so and inside our
function
what we want to do is we just
want to
create a basic flip flop type of switch
so if this
our switch variable is equal to zero
what we want to do is
make it into a one so let's make it
into one like so and if
that is not the case we just want it to
be zero again
after that uh this is where we should be
using our module
log update and inside that we should
give our array with
the switch
index yeah that would be fine so if we
run that oh actually before we run that
we
obviously need to give our
timeouts so one second for timeout
should be good so if i run that what we
will be seeing
we should be seeing is fizz and buzz
continuously updating in our terminal so
let's look at that if it is the case
and as you can see every second it
updates to
fizz buzz face buzz and continues on
like that
so that is basically it for the video
this is
an introduction to basically chalk
and log update modules so hope you like
it
if that is the case please make sure to
hit the like button and consider
subscribing
see you next time take care