-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
} | ||
} |
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; | ||
|
||
app.use(express.json()); | ||
|
||
|
||
app.get('/', (req, res) => { | ||
res.status(200).send('Hello from backend to frontend!'); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}`)); |
There was a problem hiding this comment.
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!