Welcome back in this lesson I'm going to introduce Express which is the framework that we're going to
use throughout the rest of this course.
There are three main questions that I want to answer here.
The first one is what is a framework.
How is it different from a library.
The next is what is express.
And then the last one is Why are we using EXPRESS Why are we teaching express in particular.
Let's get going and we'll start by talking about what a framework is.
Up until this point we've used a few libraries including Jay equerry and bootstrap but also some people
would refer to the Cat me and knock knock jokes packages as libraries are definitions so far of a library
is that it's code that someone else wrote that we can include in our application and use.
So that's also what frameworks our frameworks are code that someone else wrote.
Usually a lot of people wrote because it's a lot more code that we can use instead of our application
.
But the way that we use them is very different.
So I have a great stack overflow post I'm going to pull up and it talks about the difference between
a framework and a library.
And this first answer really nails it on the head so I'll just read a few of the more important lines
including this first one.
The most important difference and in fact the defining difference between a library and a framework
is something called inversion of control.
What does this mean.
Well it means that when you call a library you're in control but with a framework that control is inverted
.
The framework calls you and then I'll skip down to this section here.
Basically all the control flow is already in the framework and there's just a bunch of predefined white
spots that you can fill out with your own code a library on the other hand is a collection of functionality
that you can call those two excerpts do a great job of summarizing the differences both frameworks and
libraries are external code that you're including in your own application but a library is something
that you're in control of if you want to use a library you can use one method 10 methods just like if
we include a query.
It's up to us which parts of it we use.
We might only use a few of the methods for animations or we might use 100 different methods with a framework
on the other hand.
We give up a little bit of control where if we use a framework like the one we're going to use which
is express We have some decisions that have been made for us that we have to abide by in order to use
the framework I like to think of it a little bit like Mad Libs where a framework gives us the basic
scaffolding and then we fill in the blanks with the important parts.
But I want to make it really clear the point of a framework is not to replace any sort of creativity
or homogenize the way that all applications work.
What frameworks really do is they take all of the common stuff that we do in every application all the
setup work all the basic things that every app needs and it just prepackage it all up so that we can
use it and get started on new apps without having to do all the basic ground work every single time
.
So when we read an application we just focus on the important content of the application.
What makes it unique.
Rather than spending time working on the very very basic stuff every single time we make a new application
.
So as I mentioned Express's what were going to use Express is a framework.
And in particular its a web development framework.
There are all sorts of different frameworks out there.
There are frameworks that help you make videogames or frameworks that how we make mobile apps and there
are tons and tons of frameworks to make web applications.
Express is one of those other frameworks that exist across all languages.
Include things like flask for Python Django for Python rails for Ruby Sinatra for Ruby and there are
even other Noad web development frameworks like sales.
J.S..
Which is another relatively popular one but Express is the one that we're going to use.
And let me just show you before we talk about why we're using it.
Let me go over to an application they have created.
This is another cloud nine instance I have running and this is an express app.
So all of this right here all of these files and directories are all part of an express application
and by using Express I was able to focus on just writing the application code not having to focus on
all the basic legwork of creating a server and dealing with routes and connecting to a database and
all the basic steps that every app requires instead of just focused on the application content.
Shortly we'll be creating our own apps that look like this where we have 20 30 different files in 10
or 15 different directories all sorts of different packages that were installing and including There
will be tons of moving pieces but Express is the glue that keeps everything together.
What I'm saying will make a lot more sense once you actually start writing apps and the next video and
you see what Express actually does for you.
So the one other thing that I want to talk about is why are we using Express.
I said there are a lot of different frameworks.
Why are we going with Express.
My answer is very similar to the answer I gave as far as why were learning node why were using javascript
on the backend instead of Ruby or Python or ph P in that theres a few reasons.
The first reason is that express is by far.
Without a doubt the most popular node web development framework.
It has the most downloads on NPM it has and most people contributing to it on get habbe.
Its just the most widely used node framework which is always a great reason for us to use it not just
because its trendy not just because people say that its good but more so because theres lots of tutorials
and theres a big community of people who know express who are writing about and talking about it which
is always something you want to look for when you're learning a new technology.
And the second reason that we're using Express is a little more complex to explain a need to give you
a little bit of backstory on the different types of frameworks that we can have.
There are two terms that people will use to describe frameworks.
Those are heavy and light or heavy weight and light weight heavy weight and light weight.
Referred to how much your framework does for you versus how much you have to do yourself.
So think of it if were talking about Mad Libs again a framework thats heavyweight really has a lot of
text in there and just a few blanks that you feel in a framework thats lightweight has a lot more blanks
a lot more frequently across the page where you're expected to go in and fill in your own code more
often.
So where express fits into all of this is that it's a very lightweight framework so it doesn't hide
things from you it doesn't do things you don't expect it to do.
You use Express and you know exactly what you're getting versus a framework like rails which I love
rails by the way I'm not trashing it but when you teach people rails it's really problematic because
it does so much for them and you can make apps fast.
But students don't understand what it's doing because they've never seen a framework that doesn't do
that for them.
So I've noticed that students who learn with a framework like Rails as their very first framework a
very heavyweight framework where they only fill in a few blanks they end up being very reliant on rails
and they don't understand the underlying concepts and they can't work with a framework that isn't Rail's
or at least it takes more effort for them to learn the rails way of doing things.
So Express on the other hand is much lighter weight and that doesn't mean that it's less powerful or
that you can't use Express to do things that you can do in Rails.
It just means that you need to understand how things work in order to get things done in Rails.
You can make an awesome web app without really knowing what the heck you're doing.
So in my mind that's really the main reason that I'm teaching express Yes it's popular and there's a
large community behind it but more importantly it's just a great tool to learn how to make web apps
with blessing I'll do here is show you the official express home page first thing that you might notice
is this little blurb here.
That express is a fast and opinionated minimalist web framework for Noj Yes.
And this word unin piñon it'd when it's referring to a framework.
What that means is that it's flexible.
It lets you do things in the way that you want versus rails if you use Rails Rail's it's extremely opinionated
.
You have to make files named a very particular way they have to go in a very particular place with Express
.
We have more freedom to decide how we're going to structure things.
You can also see that we install it just like any other package and PM install Express will learn what
the dash dash save means in the next video.
And to finish up on here I highly recommend you check out the Getting Started Guide.
If you have any questions and there are some other great resources on here as well including their official
guide API reference some advanced topics that we'll talk about at the end of the course.
The great list of resources including books and blogs some great tutorials and a glossary that will
come back to you later in the course as well.
All right so let's wrap this up.
What is a framework.
How is it different from a library framework it's just a bunch of code that someone else has written
just like a library is except when we use a framework.
We have less control.
And the goal of using one is to make our development of whatever it is a game a web app a mobile application
.
We want to make things faster so we use a framework.
Express is one framework for web development and it happens to be a node framework.
There are other web development frameworks out there but we're using Express and we're using it because
it's popular.
Lots and lots people use it.
There's great documentation and tutorials.
It's widely used and supported but also and even more importantly it's a great first framework for someone
to learn all right in the next video we're going to install Express and make our first simple application