From b6ec7c47f88be3e32486007f035f41eac48ed9d6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1N0FNIS\\elias" Date: Fri, 27 Sep 2024 02:06:00 +0200 Subject: [PATCH] Moved unrelated files to a new branch and removed those commits from the PR. Fixed indentation to make the code clearer. Moved app.use(express.json()); to be grouped logically with other setup code. --- assignments/hackyourtemperature/package.json | 19 +++++++++++++++++++ assignments/hackyourtemperature/server.js | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 assignments/hackyourtemperature/package.json create mode 100644 assignments/hackyourtemperature/server.js diff --git a/assignments/hackyourtemperature/package.json b/assignments/hackyourtemperature/package.json new file mode 100644 index 000000000..312602620 --- /dev/null +++ b/assignments/hackyourtemperature/package.json @@ -0,0 +1,19 @@ +{ + "name": "hackyourtemperature", + "version": "1.0.0", + "type": "module", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "keywords": [], + "author": "Elias", + "license": "ISC", + "description": "", + "dependencies": { + "express": "^4.21.0", + "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..d7c01bb86 --- /dev/null +++ b/assignments/hackyourtemperature/server.js @@ -0,0 +1,19 @@ +import express from 'express'; +const app = express(); + +app.use(express.json()); // Moved this line up + +// Set server to listen on port 3000 +const PORT = 3000; +app.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); + +app.get('/', (req, res) => { + res.send('hello from backend to frontend!'); +}); + +app.post('/weather', (req, res) => { + const cityName = req.body.cityName; + res.send(`You requested the weather for: ${cityName}`); +});