Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Express Basics!
You have completed Express Basics!
Preview
Install Express on your computer.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
The first thing to do when
starting a new Node.js project
0:00
is to install the project's dependencies.
0:04
Dependencies are third-party Node
modules used in your project.
0:06
Modules, like Express,
give you a lot of power, so
0:11
you don't have to write a complete
Web application from scratch.
0:15
Let's take a look at how to start a new
Node project, and install Express.
0:19
First things first, I'm teaching this
course using three primary applications
0:25
on a local machine, a text editor,
a terminal or console, and a web browser.
0:30
I have my terminal open here,
I'm on a Mac.
0:36
If you're using Windows,
you can use a command prompt, PowerShell,
0:39
or other command line utility.
0:43
Common free text editors
are Visual Studio Code and Atom, but
0:45
there are many to choose from.
0:49
And you're obviously using a browser
since you're taking this course.
0:51
In addition to the above applications,
you'll need Node and
0:55
NPM installed on your local machine.
0:59
See the Teacher's Notes for
links to installation guides
1:01
if you need help installing Node and
MPM on your machine.
1:05
We'll create all files that we need from
scratch as we go through the course.
1:09
If you follow along with me,
1:14
you should have the same results
as you see in the videos.
1:16
However, if you want to jump
somewhere later on, you can.
1:19
Just download the project files and unzip
them and find the appropriate folder that
1:22
corresponds with the video
that you're starting out.
1:26
I'd recommend copying that folder and
1:30
working with that copy in
case you want to start over.
1:32
You can always just throw it away and
then copy the relevant folder again.
1:36
Check the Teacher's Notes for some
additional tips using the project files.
1:41
Without much further ado, let's begin.
1:45
In my terminal, I'll create a directory
that will hold the Express application
1:49
using the mkdir command.
1:53
Let's call the directory flashcards,
and open the directory
1:56
by using the command cd, and
then the directory name, flashcards.
2:01
Now, to initialize a Node application,
you can use npm init -y.
2:06
The -y just accepts all
the default options.
2:13
Otherwise, you'd have to
type them all by hand.
2:17
For more on using NPM,
check the Teacher's Notes.
2:20
With our package.json generated,
we can install and save Express.
2:23
We'll be using the latest version of
Express at the time of recording, 4.15.2.
2:31
--save adds this package to the
package.json file making it super simple
2:39
to install the applications
dependencies on another machine.
2:44
Now, lets add some code for
our application.
2:49
Depending on the text editor that you'd
like to use, you can usually create
2:52
a new file and launch it in the new
editor from the command line.
2:56
For example, for Atom, you can type atom,
and then space, and then the file name.
3:00
I prefer Visual Studio code, and
its command is code instead of atom.
3:10
Check the documentation for your editor
if you'd like to use this convenience.
3:18
Otherwise, you can simply open
the text editor manually and
3:22
create a new file from the menu.
3:27
I'll type code.app.js.
3:30
You can see the new file
open in the editor.
3:33
App.js will be the main file that
holds our Express application.
3:36
In order to use Express, we must add
it using Nodes require statement.
3:41
The module is called Express and
3:52
it is the parameter that I pass
into the require function.
3:54
In this case,
Express is also an ideal variable name.
4:01
And that is the variable that I
will assign the required module to.
4:05
From this point on, I can use the variable
express to access all the methods and
4:10
properties of the Express module.
4:15
Great work, Express is installed, imported
and ready to be used in our application.
4:18
Next, you'll build your
first Express application.
4:24
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up