Instructor: In this section,
we're gonna start working on the Node JS web application.
If you are not familiar with Node JS
or you don't know any JavaScript
and you don't want to know any JavaScript,
that is totally fine.
You can pause the video right now.
Skip to the next section where I will have a text link
for you to download the two files that you're going to need.
So totally fine if you don't wanna write
any JavaScript at all.
Otherwise, stick around and we'll get started on this
tiny web application.
So to get started, I'm gonna first flip
back over to my terminal.
You'll notice that I'm still inside of
that Redis image directory.
I'm gonna go up one directory
and then I'll make a new project folder
and we will call this how about Simple Web?
Because it's going to be a rather simple,
straightforward web application.
I'll then change into that directory
and then I'm going to again start up my code
editor inside there.
Now a quick reminder, I was able
to use the code command right here
because I've set up Visual Studio Code
to be executed from my command line.
So if you don't have that set up, totally fine.
All you really need to do right now is open up your code
editor based on that simple web directory
that we just created.
Then inside of here, we're gonna create first a file called
Package.JSON.
Inside this file we're gonna put together a little bit
of configuration to describe
how our node application is going to work exactly.
I'm gonna first begin by placing a set of curly braces
and then inside there I'm gonna place a key
wrapped in double quotes.
And the first section we're going
to put together is gonna list out all
of the different dependencies
that our application needs to run correctly.
Notice how I'm wrapping the word dependencies inside
of a set of double quotes.
I've got a colon afterwards
and then I open up a curly brace object.
Then inside that set of curly braces,
I will put down another set of double quotes.
And I'm gonna say that in order for our application
to work correctly, we need a copy of express.
I'll then put down a colon
and then for the version, I'm just gonna put a star
to say we can use any version of express out there.
We don't care.
After that, I'm then gonna put a comma on this line
right here.
And then I'll add in one more section.
This is going to be a section that we will call scripts
and this will contain some of the different scripts
that you can run to get our application up and running.
I'm gonna open up another set
of curly braces just like we did a second ago.
I'll put a set of double quotes
and we're gonna create a script called Start.
Anytime that someone runs the start script,
we are going to execute node index.JS, like so.
This right here is going to be
what ultimately starts up our server and gets it running.
Alright, so that's it inside of the package.JSON file.
So we have specified dependency
and we have created a single script.
I'm now gonna make sure that I save the file
and then I'm going to close it
and create a second file inside the same directory.
And the second file I will call index.JS.
So inside of here, we're gonna first begin by requiring in
the express library that we just marked as a dependency,
I will then use the express library
to create a new app like so.
And then we are going to set up one single route handler.
We're gonna say app.get.
I'll pass in a string with a forward slash.
As a second argument, I'll pass in an arrow function
that gets called with a request and response object
and open up a function body after placing a function arrow.
Then inside of here we'll do res.send
and we're gonna send back a message of 'Hi there'.
So now anytime someone visits the root route
of our application, we are going
to immediately send back a string that says simply
'Hi there'.
And so ultimately when we run our application,
my expectation is that in the browser we should be able
to visit this running web application
and see, 'Hi there' up here on the screen.
Now the last thing we have to do is set up our application
to listen on a port.
So down at the bottom of the file, I'll say app listen
and I'll specify the port that we are going to be listening
to as 8080.
As a second argument, I'll pass in an arrow function
like so.
And then finally, after the app starts listening
to this port correctly, we will print out a little message
that says listening on port 8080 like so.
And then I'm going to make sure that I save this file.
Alright, so that's pretty much it.
We've got our package.JSON file
that defines some configuration around our project.
And then we've got the index.JS file
that contains the actual server logic.
So we're gonna take a quick pause right here.
When we come back the next section,
we're gonna start talking about how we're going
to put together our docker file.
So quick break and I'll see you in just a minute.