Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
You may be asking "OK, so I can write JavaScript on the server-side, so what's the big deal?" Let me answer that for you.
You may be asking, okay so I can write
JavaScript on the server side, but
0:00
what's the big deal?
0:03
Why shouldn't I use other languages
that are all ready being used on
0:04
the server side?
0:07
Here's an analogy to that will help
illustrate why you'd want to use Node.js.
0:09
Imagine I have an assistant that
I gave a stack of invoices to.
0:13
I asked them to send
them out on my behalf.
0:17
The assistant sends the first invoice
out and waits for the check for payment.
0:20
Once they receive the payment,
they deposit it in the bank and
0:24
send out the next invoice.
0:27
Now this isn't good for me, I'm not
getting paid as quickly as I could.
0:29
This is blocking me from
receiving my payments,
0:33
blocking my business from growing, and
blocking me from getting stuff done.
0:36
I've got two options, getting more
assistants who will do the same thing or
0:41
get a new more efficient one.
0:45
The new more efficient assistant
would send out all invoices and
0:47
process each payment as
soon as it comes in.
0:51
I know some of my customers pay quicker
than others, so I wouldn't want to wait to
0:54
deposit the payments in the same
order I send out the invoices.
0:58
I want to deposit them as
soon as I receive them.
1:03
This assistant knows that.
1:05
Not only is this assistant saving me a lot
of resources by not having to employ
1:07
extra inefficient assistance.
1:12
But while they're waiting for payments
from my clients, they're free to do
1:15
other things to assist me, like sending a
thank you note when a payment is received.
1:18
You can say that this assistant is
non-blocking, since they don't hinder me,
1:24
and improves my relationships
with my existing customers.
1:28
Most languages and
frameworks work like the first assistant,
1:32
handling one set of tasks
from beginning to end
1:35
before repeating the process again doing
the same set of steps for another task.
1:38
This sort of behavior manifests
itself most noticeably
1:44
when you're doing a couple of
things in a single web request,
1:47
like querying a database and
uploading files to be saved to disk.
1:50
Imagine having a popular social network
that required a profile image on sign up.
1:54
Imagine how frustrated your users
would be if they had to wait for
1:59
all of the user images
to be uploaded first.
2:03
It would be super frustrating, and I don't
think you'd be popular for that long.
2:06
Languages that queue up requests, and
process them one at a time like this
2:09
are known as blocking languages, since it
blocks the handling of other requests.
2:15
Often developers scale these types
of applications by running more than
2:20
one instance of their web applications.
2:24
These instances are known as workers.
2:26
However, Node.js works like the second,
more efficient system, doing what it can
2:29
do now, responding to requests while
it waits for other tasks to finish.
2:34
This often means when certain types of
applications are ported to Node.js, you
2:39
don't necessarily require as much system
resources to perform the same tasks.
2:43
Sometimes one Node.js worker can be even
more responsive than the other languages.
2:49
Node.js is non-blocking and
that's why you'd want to build JavaScript
2:55
applications on the Node.js platform
over other languages and platforms.
2:58
It's fast and efficient.
3:03
It doesn't take up as many computer
resources by the computers processing
3:04
power or memory.
3:09
You need to sign up for Treehouse in order to download course files.
Sign up