Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assignments/hackyourtemperature/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions assignments/hackyourtemperature/.idea/hackyourtemperature.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions assignments/hackyourtemperature/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions assignments/hackyourtemperature/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions assignments/hackyourtemperature/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "hackyourtemperature",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"dev": "nodemon server.js"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you use nodemon

},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"express": "^5.1.0",
"nodemon": "^3.1.10"
},
"dependencies": {
"express-handlebars": "^8.0.3",
"node-fetch": "^3.3.2"
}
}
23 changes: 23 additions & 0 deletions assignments/hackyourtemperature/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import express from 'express';

const app = express();

app.use(express.json());

//GET request that sends the message [hello from backend to frontend!] to the client
app.get('/', (req, res) => {
res.send('Hello From Backend to Frontend');
});

//5.1 Adding a POST request

app.post('/weather', (req, res) => {
console.log(req.body);
const { cityName } = req.body;
res.json(`the city name is ${cityName} `);
});
Comment on lines +14 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the successful response requires the presence of a certain attribute in the request, it's a good practice to validate the request in your handler. What should the application do if cityName is missing?

This was not mentioned as a requirement in the instructions, so don't worry too much about it, but it's good to start thinking about these things.


//
app.listen(3000, () => {
console.log('Server on Port 300 is running');
});