- be sure to have
control c
your previous app if you were running one before starting this new activity
- Initialize node in this directory (
npm init1
) 2.installexpress
- create an entry point (
index.js
) file - inside
index.js
, require express and save it to a variable namedexpress
- create a variable named app, and set it equal to
express()
- have app listen on port 3000
- once it's listening, log "Hello, Seattle. I'm listening..."
- test it by going to http://localhost:3000
- create a GET route for
/frasier
- it should send a response of "Once in prep school, the Existentialist Club once named me 'Most Likely to Be'"
- test the
/frasier
route by going to http://localhost:3000/frasier - create a GET route for
/niles
- it should send a response of "You know, sometimes I wonder if I'm not just in psychiatry for the money"
- test the /niles route by going to http://localhost:3000/niles
- create a GET route for
/daphne
- it should send a response of "Well, have fun. I'm off to stick my head in the oven."
- test the
/daphne
route by going to http://localhost:3000/daphne - create a GET route for
/roz
- it should send a response of "Let me make it easy for you. Freaks! Freaks on line 1. Freaks on line 2! Freaks! Everywhere!"
- test the
/roz
route by going to http://localhost:3000/roz - create a GET route for
/martin
- it should send a response of "You may think it's tough being middle-aged, but think about me. I got a son who's middle-aged."
- test the
/martin
route by going to http://localhost:3000/martin
Are URLs case sensitive? Let's test:
- create a GET route for
/Scrappy
- it should send a response of "woof"
- test the
/Scrappy
route by going to...
- test the
- http://localhost:3000/scrappy - what happened?
- http://localhost:3000/Scrappy - what happened?
The topic is yours. Try to do it all from memory (in a new directory - you wont have to turn this part in!)
-
Create a basic app with multiple routes
-
When it comes time to do res.send, instead of just text, send html
-
To get res.send to work with line breaks in the html, change single/double quotes to backticks
res.send(` <html> <body> <h1>Oh ha!</h1> </body> </html> `);
This deliverable was adapted from SEI-MAE