diff --git a/assignments/HackYourTemperature/package.json b/assignments/HackYourTemperature/package.json new file mode 100644 index 000000000..8bf1bf4e2 --- /dev/null +++ b/assignments/HackYourTemperature/package.json @@ -0,0 +1,18 @@ +{ + "name": "hackyourtemperature", + "version": "1.0.0", + "main": "index.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "express": "^4.21.2", + "express-handlebars": "^8.0.1", + "node-fetch": "^3.3.2" + } +} diff --git a/assignments/HackYourTemperature/server.js b/assignments/HackYourTemperature/server.js new file mode 100644 index 000000000..5d9aeb3fc --- /dev/null +++ b/assignments/HackYourTemperature/server.js @@ -0,0 +1,24 @@ +import express from "express"; + +const app = express(); +const PORT = 3000; + +app.use(express.json()); + +app.get("/", (req, res) => { + res.send("hello from backend to frontend!"); +}); + +app.post("/weather", (req, res) => { + const cityName = req.body.cityName; + + if (!cityName) { + return res.status(400).json({ message: "City name is required." }); + } + + res.status(200).json({ cityName: cityName }); +}); + +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +});