From bd6c2ce8ef5449a544c4d0a2b8fa17a93176b73a Mon Sep 17 00:00:00 2001 From: Ahmad Saadeddin Date: Wed, 29 Oct 2025 18:13:58 +0100 Subject: [PATCH] node-w1-assignment --- assignments/HackYourTemperature/.gitignore | 1 + assignments/HackYourTemperature/package.json | 19 +++++++++++++ assignments/HackYourTemperature/server.js | 30 ++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 assignments/HackYourTemperature/.gitignore create mode 100644 assignments/HackYourTemperature/package.json create mode 100644 assignments/HackYourTemperature/server.js diff --git a/assignments/HackYourTemperature/.gitignore b/assignments/HackYourTemperature/.gitignore new file mode 100644 index 000000000..40b878db5 --- /dev/null +++ b/assignments/HackYourTemperature/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/assignments/HackYourTemperature/package.json b/assignments/HackYourTemperature/package.json new file mode 100644 index 000000000..7e4549be2 --- /dev/null +++ b/assignments/HackYourTemperature/package.json @@ -0,0 +1,19 @@ +{ + "name": "hackyourtemperature", + "version": "1.0.0", + "description": "", + "main": "server.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "express": "^5.1.0", + "express-handlebars": "^8.0.3", + "node-fetch": "^3.3.2" + } +} diff --git a/assignments/HackYourTemperature/server.js b/assignments/HackYourTemperature/server.js new file mode 100644 index 000000000..1a0779c85 --- /dev/null +++ b/assignments/HackYourTemperature/server.js @@ -0,0 +1,30 @@ +import express from 'express'; + +const app = express(); +const PORT = process.env.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; +if (!cityName) { +return res.status(400).json({ + success: "false", + message: "City name is required", +}); +} +res.status(200).json({ +success: "true", +message: "City received successfully", +Data: { + City: `You entered: ${cityName}`, +}, +}); +}); +app.listen(PORT, () => { +console.log(`Server running on http://localhost:${PORT}`); +}); \ No newline at end of file