Skip to content

Assignments week 1 Ilias Khugaev #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions assignments/hackyourtemperature/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "hackyourtemperature",
"version": "1.0.0",
"main": "server.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"description": "",
"dependencies": {
"express": "^5.1.0"
}
}
21 changes: 21 additions & 0 deletions assignments/hackyourtemperature/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import express from 'express';

const app = express();
const port = process.env.PORT || 3000;

Choose a reason for hiding this comment

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

Really nice use of environmental variables here!


app.use(express.json());


app.get('/', (req, res) => {
res.status(200).send('Hello from backend to frontend!');
});

Choose a reason for hiding this comment

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

I would remove the 3 white lines, and keep only 1. Good work on separating the functions and leaving space to improve readability. By convention we usually leave one line between our functions to keep a balance between readability of our code and file size. You can imagine if we had more functions in this file and each had 3 white lines separating them it would become harder and harder to scroll down and move between functions!

Copy link
Author

Choose a reason for hiding this comment

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

Good afternoon! Thank you for your work — you were absolutely right about res.sendStatus(200). I actually meant to write res.statusCode = 200;. Based on your comments, I decided not to add the status code explicitly, since res.send() already sets it automatically for me. Thank you again for your help!


app.post('/weather', (req, res) => {
const cityName = req.body.cityName;

res.status(200).send(cityName);
});


app.listen(port, () => console.log(`Listening on port ${port}`));