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