This course has been updated! We now recommend you take the API Design in Node.js, v4 course.
Transcript from the "Introduction" Lesson
>> Scott Moss: If you've taken the V1 course, don't worry about it. I'm still going to cover things that might be new to you, it depends on how far you progressed since you've taken that course. There's gonna be some new patterns here but the skill level is still going to be around the same so don't worry, this is not an advanced course.
[00:00:18] I'm still gonna be showing how to build from scratch with a different approach than what I did last time. And then of course, tomorrow we'll be doing GraphQL, learning how to build it side-by-side and on top of and all that good stuff. But let's get right into it, so my name is Scott Moss.
[00:00:57] So [LAUGH] I worked at a few tech companies in the Bay while I was working in open source before I started some of these companies. I have taught over, I don't even know the number, but I have taught a lot of people how to write code either on different platforms like [INAUDIBLE] Masters or at different schools in the Bay.
[00:01:31] [LAUGH] That is like the worst thing ever? Do not try to write a book. I'm also into fashion, anime, games, fitness, and music. So if anybody's into any of that stuff, come holler at me.
>> Speaker 2: Mario said, Scott's always looking so fly.
>> Scott Moss: [LAUGH] Appreciate it. I've been super following Dragon Ball super lately if anybody's been watching it.
[00:01:52] Did you see last week's episode? I don't wanna spoil it. [LAUGH] So good. But yeah, that's a little bit about me. So let's just jump right into it. I'm really excited about this. What is Node Js? Anybody wanna tell me, all right no, don't look at it. Anybody wanna tell me what is their definition of NodeJS?
>> Speaker 4: Server, async.
>> Scott Moss: Server, async, I hear the buzz words, it's coming.
[00:02:57] That's basically what Node is. But because of that, because you're no longer in a browser, which has security issues around, touching the file system and stuff like that, we needed a way to actually do that with Node. Node has some different things on top of that, so you might see something like a module system, and things like that but basically its just V8 outside of the browser.
[00:03:18] With that though you can build things like servers and stuff like that. So, it's created by a person named Ryan Dahl he's currently at Google. I think he is working on like tensor flow right now, some machine learning stuff. It's maintained by the Node.js Foundation which has been in the news as of late.
[00:03:36] You read it, it's pretty funny. It is open source, yeah, but good luck trying to contribute to it. [LAUGH] Used by pretty much everyone. Click on that link and you can see what I mean by everyone. Pretty much everybody uses Node JS, somehow, someway. Maybe not for API's, but for other things.
[00:04:11] No? Okay, cool. So http in Node. Node comes with like a built-in module system like I said before, so the browser hasn't introduced modules yet. At least not in like the latest browsers, I think maybe some edge version of some browser might has module at this point but they don't have modules yet so you got to use some type of build system.
[00:04:35] But node has a module system built in, and with that there is a built in module that we can use in node to actually create network based apps, it's called http, that's the name of the module. If you are using number four, you know you can use the require function to require a module.
[00:04:48] Which basically just loads it into your closure. There's one called http, so if you were to require http you would get an http object that has all these methods on it that'll allow you to build network based applications. But you shouldn't use it, because it's just a library, it's not a framework.
[00:05:05] And relatively speaking, it is low level. I say low level because like, relatively speaking for node it's low level. But for other frameworks, rust or something, it's probably not that low level. But yeah you probably shouldn't use it, there's a lot of things you have to do. Managing sockets, streaming, error handling, a lot of stuff you have to set up manually.
[00:05:22] And if you're writing multiple apps, you'll be doing that every single time, eventually you'll build your own framework with your own abstractions. When you should've been, there's already one out there, should've just used that. So do not use that module unless you need some lower level thing that's happening.
[00:05:38] I do not recommend using the http module. Instead, you should use a framework that is based off that module that has a lot of people from the community working on it, and making it better. So good luck using that. You still need to develop abstractions around the http module to build servers.
[00:05:53] Any questions on that? Just don't use it. So, some node server frameworks here, can't list all of them cause there's so many of them. I'm just gonna list some that I found from my research. So connect seems to be like, connectors like the original OG server framework for note.
[00:06:17] Pretty much all the good frameworks have drawn inspiration from Connect or actually use it inside their code at one point. So Connect is like, it's a framework but it's like a lower level framework as well. People built frameworks on top of Connect. Then they build frameworks on top of that.
[00:06:33] It's kinda crazy. Connect is like one of those foundational frameworks. Express the one we will be using in this workshop. It was originally based of Connect. And then [INAUDIBLE] Express three, I think they got rid of the dependency of Connect. They still kept the same syntax. They built their own version of Connect.
[00:06:50] Koa, created from the express creators is like Wxpress, first start off as like a user generators but then when nobody cared about generators anymore now they use. So, it's basically that. Check it out if you want. Hapi is another another framework different approach. Sells. Yeah, Sails was like an attempt to do a rails for node.
[00:07:13] It's based on Express. Check it out. And then, there's so many more just like some new types [INAUDIBLE] popping up. There's just so many things out there it's ridiculous, but Express is pretty much the defactor of framework for the Node community. It's pretty much what everybody uses. If you ever downloaded a plugin for Node, they probably have an Express version for it.
[00:07:31] It can be a safe bet to use Express with Node.