So now that we know what the problems
with this static frontend-site are,
let's migrate it to a dynamic site
that uses our own server-side code,
because that's what we need ultimately.
And therefore, I'll close this frontend-site folder for now
and get back to this app.js file.
In here, we now want to create a brand new Express server,
so a NodeJS server with help of the Express library,
which we already used before.
And then we want to set up a couple of routes,
so a couple of paths that we handle
and then sent back different responses,
enable the submission of this form, and so on.
Now, therefore, first of all,
we should make sure that Express is installed.
And in this starting project,
which I provided to you,
Express already is specified as a dependency.
So if you ran npm install, which you should,
then you got Express installed already.
And therefore, we can then go back to app.js
and create our Express web server here.
Now, definitely feel free to try this on your own,
setting up a basic server
that does not yet serve the HTML files,
just a dummy server that handles one route
and sends back a dummy response.
After a short pause,
which I give you to pause the video
and try this on your own,
we'll do this together.
So did you succeed?
Let's now do that together.
And for this,
we'll, first of all, import require express
with that require function like this
and store it in a constant or a variable.
Then you learned that Express is actually a function
that we can execute,
and therefore, I'll call express as a function
and store the result in a constant named app.
As you learned, that's not a must-use name,
but it's a commonly used name,
since we refer to Express servers as apps or applications.
Now on this app object,
we can now call the listen method
to start listening for incoming requests,
for incoming network traffic on a certain port.
And during development.
I will again use port 3000 as we did it before
in this course.
Now this sets up a server that listens to requests,
but in order to really have a useful server,
we should have at least one route,
one path after our domain, which we support.
And for that, I'll set up some dummy path here
with app.get, let's say,
to listen to incoming get requests
where I just listen to slash nothing,
so just localhost 3000 slash nothing
to then do something.
And the something I want to do here
is then to find in this anonymous function which I create,
which receives a request object and a response object,
and we can use this response object to send back a response.
And there, I'll just sent back
the good old "Hello World" response,
though we are going to change this
throughout this course section.
And now with that setup,
we got our first basic dummy Node Express server,
and we can now start this server.
And for this, I got Nodemon installed already.
It was a devDependency listed here in this project.
And I got this start script prepared already
in package.json.
And therefore, as you learned
at the end of the previous course section,
we can now open this integrated terminal here
in Visual Studio Code
and then simply start this script with npm run start.
Or since start is a reserved special type of script name,
we can also just run npm start like this
and start this Nodemon server,
which will keep on watching for changes
and which will restart the server
whenever we do change our code.
And now with that,
we can go back here and instead of loading this site,
which was served by this Live Server extension,
so this static site that we have here,
I will now visit localhost 3000 slash nothing,
and we should see "Hello world!" here.
And that's now this dummy starting Node Express server
with which we will continue in the next lectures
to now migrate this static site into this server
so that it can be turned into a dynamic site
where dynamic content can be generated and served.