Skip to content

Assignments week 1 Oleksandr Starshynov #2

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 3 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
19 changes: 19 additions & 0 deletions hackyourtemperature/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"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",
"description": "",
"dependencies": {
"express": "^5.1.0",
"express-handlebars": "^8.0.2",

Choose a reason for hiding this comment

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

While you have imported the handlebars templating system, you have not used it in the assignment, please implement/use this for templating/displaying the response to the root ("/") GET request. as a hint, your return line should look like 'res.render('home')'

"node-fetch": "^3.3.2"
},

Choose a reason for hiding this comment

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

(Minor,non-blocking) we are missing the use of the nodemon package

  1. Add it to the dev-dependancies.
    Can you add a line to the "scripts" option showing how you would run nodemon
    Adding your "run" commands to the script's options has two main benefits:
    -> It enables easier collaboration between teammates, as everyone on the team uses the same commands.
    -> It saves time rather than having to remember and write out (sometimes long) commands.

"type": "module"
}
26 changes: 26 additions & 0 deletions hackyourtemperature/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import express from 'express';
import fetch from 'node-fetch';

// Create an instance of express
const app = express();

// Middleware to parse JSON
app.use(express.json());

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

// First POST endpoint
app.post('/weather', (req, res) => {
const cityName = req.body.cityName;
console.log('Received city name:', cityName);
res.send(`You sent: ${cityName}`);

Choose a reason for hiding this comment

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

Replace this with an express-handlebars rendered page.

});

// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});