A developer's Blog Log #3

...Jason Nutt 02/18/2021

Headline day 3/ Getting server setup ...

A re-re-iterated version of compiled notes & learning

From Treehouse, YouTube, DevEd, Node.js Docs and more...

Blog # 3 Now let's write some code!...

Let's get up to speed with where we should be...

We should have VS code open and be inside of the Terminal YES?

We should also have installed express with the command

npm install express --save

Now, lets add some code for our application Depending on the text editor

that you'd like to use, you can usually create a new file and launch

it from the command line, Andrew talks more on this but I am going to create OUR new file inside the text editor's menu instead

The reason, to be honest, is that MY VS code terminal was not allowing me to use the shortcut, but that's a good teaching point...

There is almost ALWAYS another way if one way is unable to be utilized for a,b or c reasons.

Check the documentation for your editor if you'd like to use this convenience

Now go ahead and creat an empty javascript file named app.js using either of these methods

Awesome NOW let's write some code....

app.js will be the main file that holds our Express application.

In order to use Express, we must add it using Nodes require statement

const express = require('express');

The module is called Express and it is the parameter that I pass into the require function.

In this case, Express is also an ideal variable name

And that is the variable that I will assign the required module to.

From this point on, We can use the variable express to access all the methods and

properties of the Express module.

Great work, Express is installed, imported and ready to be used in our application.

Great I passed the quiz and workshop, So now we can keep going!

Next, we'll build our first Express application.

Let's set up the express server now.

We have already required the Express module and assigned it to the variable express.

Let's create our app.

To create an Express application we can just call express().

The express function returns an Express application.

Let's assign the Express application to a new variable called, app.

const app = expess();

This app is the central part of our application.

We'll extend it throughout this course by adding routes, middleware, and other settings.

The first thing we're going to do is setup the development server using the listen method.

I can give this one parameter which is the port number 3000.

app .listen(3000);

Believe it or not, we have an Express app

This code will create a server, and when I run it, the server will run on my machine.

And I can send it requests through a special URL called localhost

At this point we SHOULD be able to type "localhost:3000" in the browser and hit return

If you get a message that says Cannot GET /...this is a good thing...

It only means that we have not told express HOW to respond to any requests yet.

Express handles requests through routes...This is the topic of the next Blog...

And we will build our express application while we learn about Routes in express.

Thanks to Andrew Chalkley for amazing instruction that you may find here...

Express Routing

If I missed anything, which I am fairly certain I did not because WE have just iterated over each line

of the video transcipt as I have been doing all this step by step. But check if you feel the need. or just want a video perspective.

And next...Routing