Previous Lecture Complete and continue  

  Hello World!

So let's get started with the first adventure. I'm in an empty folder and what I want to do I want to go ahead and select that adventure. So I'm typing the command name "expressworks" and then hit enter and I select the first one, HELLO WORLD! hit enter Now I scroll a little bit up so I can see the instructions. so what it asks me to do, it wants me to create an Express.js app that outputs "Hello World!" when someone goes to slash home so those two pieces are important and then I have also I have an instruction here how to install Express locally that's another crucial piece and the port number will be passed into pro in the process that are v2 so I don't need to worry about it.

Okay so I'm not going to reach hints just now just go ahead and create file 1-helloworld and open it in my editor. So first of all we need to import the Express js library which we would install locally a little bit later and the second line we create an express js app by Now I'm creating my first route. Route it's similar to endpoint so the first would be just a slash and then I'm outputting "Hello World!" and then I would run it on port 3000. This is not what the problem asks but I just want to show you wanted to show you this example. So let's save this file for now. And go to the terminal. I'm in the terminal and if I do a less I'll see my file but I need to install the library itself so to do that I have two options: I can create package.json or I can create a folder node underscore modules so the easiest way to create package.json is to use npm init It will ask me a few questions. I'm just keeping all of them by hitting Enter on my keyboard then I type yes and I see that I have packaged a .json file. That's great, so let's install. I'm installing version 4.11.2 because this is the library this workshop have been tested with using a later version, especially version five when it comes out, use it and use at your own risk and then I'm using --save to create a record in package.json with this exact version.

Okay so one quick thing I wanted to show you you see that node underscore module folder that's the location and compare that with the ExpressWorks location that was a global location and this is a local location. So let's do ls and we see node modules here. Now let's go to our editor so we also see in the editor that we have this library here so this should work so let's go ahead and try it come back to the terminal and we type node and name of the program. Now we'll go to the browser and we'll go to localhost port 3000 and receive "Hello World!" so this is working, so let's go to home. This is what the exercise is asking us to do so when we go to /home we should see "Hello World!" as well and this is not working so let's fix it by changing it to slash home and also there would be a different port number so we change that to whatever value is provided in case there is no value, we can just use 3000. So let's go back to the terminal.

Let's kill this process with CTRL-C and restart it. Each time you make a change you need to restart the process as well let's go to the browser we'll refresh and we see "Hello World!" So it should be passing. Now let's actually verify our solution expressworks run and the filename that will run it. Okay so no errors, that's good, so let's verify. Okay so scroll up you see the actual equals expected and you see this green path, that's wonderful and this is the official solution which is pretty much the same that we had. Another way to solve this problem was to use the wild card. I go back to the file again and substitute this with the wild card this would also work because any route will output "Hello World!" and to verify again and it says pass again. So that's all for this exercise.

Discussion
0 comments