Created
July 18, 2018 01:59
-
-
Save ukhlivanov/019b954b2cedb24edbed867079e8889f to your computer and use it in GitHub Desktop.
Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
// your code here! | |
app.get("/echo/:what", (req, res) => { | |
res.json({ | |
hostname: req.hostname, | |
query: req.query, | |
what: req.params | |
}); | |
}); | |
app.listen(process.env.PORT, () => { | |
console.log(`Listening on port ${process.env.PORT}`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Request and response object drills | |
// ================================== | |
const express = require("express"); | |
const app = express(); | |
// use express middleware to parse the request body and add it to the request object | |
// don't worry, you'll learn all about middleware in the next assignment! | |
app.use(express.json()); | |
// hint: in Postman under Body remember to select JSON instead of Text, then try doing | |
// console.log(req.body) here to show your key-value pairs from Postman in the Logs | |
function doMadLib(body){ | |
const { | |
adjective1, | |
adjective2, | |
adjective3, | |
adverb, | |
name, | |
noun, | |
place | |
} = body; | |
return ( | |
`There's a ${adjective1} new ${name} in ${place} and everyone's ` + | |
`talking. Stunningly ${adjective2} and ${adverb} ${adjective3}, all the cool kids know it. ` + | |
`However, ${name} has a secret - ${name}'s a vile vampire. \n` + | |
`Will it end with a bite, or with a stake through the ${noun}?` | |
); | |
} | |
app.post("/", (req, res) => res.send(doMadLib(req.body))); | |
// listen for requests :) | |
app.listen(process.env.PORT, () => | |
console.log(`Your app is listening on port ${process.env.PORT}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment