- Crash course
- Practice the concepts
- Prep exercises
- Node.js exercises
- PROJECT: HackYourTemperature I
Before we proceed, let's check to see if we have the latest versions of Node.js and the Node Package Manager (NPM) installed. You can do that by going to the Command Line (CLI) and running
node -v
andnpm -v
. Node.js should be at least v12 and NPM should be at least v6.
There is a great crash course available here: https://www.youtube.com/watch?v=2LUdnb-mls0. It introduces a lot of the concepts you will be practicing this week.
The problems in the practice the concepts section are designed to get you warmed up for the real exercises below. You do not have to submit your code, but you have to finish all the exercises.
In this week's interactive exercises, we'll be going back to the command line. We'll be using software from Nodeschool to do some exercises.
Go to your favorite command line interface and run the following command
npm install -g learnyounode
When it's all installed, execute the command:
learnyounode
And the menu will open up. Do exercise 1 (HELLO WORLD) until 8 (HTTP COLLECT)!
Prep exercises are exercises that you should work on before the session on Sunday. These are a little more difficult or show an important concept and as such are a great exercise to talk about with your mentor. Have a solution ready by Sunday as you may be asked to show what you did.
Inside your Node.js
fork, go to the folder week1
. Inside of that folder, navigate to /prep-exercises
. For each exercise, you will find a separate folder. The README
explains what needs to be done. There will also be some questions at the bottom to think about. Go through them before the session on Sunday as it will be covered then.
Inside of your Node.js
fork, go to the folder week1
. Inside of that folder, navigate to /practice-exercises
. For each exercise, you will find a separate folder. The README
explains what needs to be done. Go through them to practice concepts that you have learned about!
In this part of the assignments you'll be setting up the basis of your project:
HackYourTemperature
. Inside the folderassignments
, create a new folder calledhackyourtemperature
. You'll add to it every week.
In this module you'll be building the simplest of API's, starting from scratch.
Each week you'll be building a certain part of it. This week we'll get started with creating a web server, using Express.js. Inside of the hackyourtemperature
folder:
- Create a JavaScript file called
server.js
(it can be any name but this is more meaningful) - Initialize the Node Package Manager and create a
package.json
file by runningnpm init -y
- Install and load in the necessary modules for this project: they are
express
(our web server),express-handlebars
(our templating engine) andnode-fetch
(a library to handle http requests in node) - As we want to use modernJS
import
statements, add the line"type": "module"
to thepackage.json
file - Set up your web server using Express (creating an Express instance, listen to port 3000)
- Make a
GET
request to/
that sends the messagehello from backend to frontend!
to the client
After writing all this code you can verify that it's working by running node server.js
from the Command Line and checking your browser at http://localhost:3000
. The page should display the message hello from backend to frontend!
.
In this part we'll add another endpoint, with a POST
method.
- Create a
POST
route, that has as an endpoint:/weather
- To make Express aware of what data type the incoming data is (which is JSON). We do that using the
json()
method on the Express object. Using theuse()
function fromapp
, pass in thejson()
fromexpress
. - Inside the callback function of the
POST
route, get access to thecityName
and put it inside a variable. Hint: use thebody
object from the request to find it. - Send the the form input back as a response to the client
Test out your work using Postman and make sure that any time you submit something in the form, it returns as a response from the server the exact words you submitted.
If you are tired of constantly restarting your server, google the nodemon
package to see if that will be useful for you!
After you've finished your todo list it's time to show us what you got! Have a look at the following guide to see how it's done.
The assignments that needs to be submitted is the following:
- Project: HackYourTemperature I
Deadline Tuesday 23.59 CET