Skip to content

rizan-ibrahim-node.js-w1 #7

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": "index.js",
Copy link

Choose a reason for hiding this comment

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

The main field in package.json should match the actual entry point of the application, which is server.js in this case. This tells Node.js where to start the application when using commands like node . or npm start.

"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
Copy link

Choose a reason for hiding this comment

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

It's good practice to include the author name and public email in the author field, like this: Name <email-address>, though it's not mandatory.

"license": "ISC",
"description": "",
"dependencies": {
"express": "^4.21.2",
"express-handlebars": "^8.0.1",
"node-fetch": "^3.3.2"
}
}
24 changes: 24 additions & 0 deletions assignments/HackYourTemperature/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import express from "express";

const app = express();
const PORT = 3000;

app.use(express.json());

app.get("/", (req, res) => {
res.send("hello from backend to frontend!");
});

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

if (!cityName) {
return res.status(400).json({ message: "City name is required." });
}

res.status(200).json({ cityName: cityName });
});

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});