Check out a free preview of the full Introduction to Node.js course:
The "Servers" Lesson is part of the full, Introduction to Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Scott introduces how servers interact with the Node js environment.

Get Unlimited Access Now

Transcript from the "Servers" Lesson

[00:00:00]
>> Scott Moss: Okay, and that brings us into the next point, Servers. So, like I said, you have one server handling many requests from clients. That's the difference between a client app and a server, right? A client app is everybody has their own instance of the same app. A server's just one for everybody.

[00:00:13] So a server's job is to handle a request from some one, [LAUGH] typo there. Some one of the client, so a browser, a mobile app, or another server. Without considering scaling, one server intancee will handle many client requests. Compared to a client app where that code only cared about itself on the host machine.

[00:00:31] So that's a different way of thinking. They're both JavaScript, but they're completely different, so you gotta take that into consideration. And that's why asynchronous code is important, cuz if you have blocking code, code that's not asynchronous would take a long time. If you did fs.readFileSync on a file that was ten megabytes.

[00:00:48] And then you have a million people trying to hit your API, they can't until those ten megabytes are read into memory. And now you just load up ten megabytes in memory on a server that's only deployed on, I don't know, one gigabyte of RAM or something. [LAUGH] You just eat up so much memory, and then you say that's an object that's a memory leak.

[00:01:04] And then five more requests, your app's just gonna crash from a memory leak anyway. So there's just so many things you just gotta be careful of. Yeah, Node.js has built in and community packages for you to build all types of servers, so APIs, static, real-time, etcetera. Any type of server you wanna build, there's a package for it, and you're gonna see.