-
Notifications
You must be signed in to change notification settings - Fork 10
created hackyourtemperature folder, created server.js #3
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "express": "^5.1.0", | ||
| "nodemon": "^3.1.10" | ||
| }, | ||
| "dependencies": { | ||
| "express-handlebars": "^8.0.3", | ||
| "node-fetch": "^3.3.2" | ||
| } | ||
| } | ||
| 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
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. 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'); | ||
| }); | ||
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.
Great that you use nodemon