Skip to content

Assignments week 1 Ilia Bubnov #1

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ npm-debug.log
package-lock.json
yarn-error.log
*.bkp
.idea

week3/prep-exercise/server-demo/
22 changes: 22 additions & 0 deletions assignments/hackyourtemperature/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "hackyourtemperature",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon server.js",
"start": "node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"express": "^5.1.0",
"express-handlebars": "^8.0.3"
},
"devDependencies": {
"nodemon": "^3.1.10"

Choose a reason for hiding this comment

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

Can you add a line to the "scripts" option showing how you would run this.
Adding your "run" commands to the script's options has two main benefits:
-> Easier collaboration between teammates, as you will all be running the same command.
-> It save time than having to remember and write out (sometimes long) commands

}
}
20 changes: 20 additions & 0 deletions assignments/hackyourtemperature/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import express from 'express';
import { engine } from 'express-handlebars';

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.

Good use of environment variables system


app.engine('handlebars', engine());
app.set('view engine', 'handlebars');
app.set('views', './views');

app.use(express.json());
app.get('/', (req, res) => {
res.render('index');
res.send('hello from backend to frontend!');
})
app.post('/weather', (req, res) => {
const cityName = req.body.cityName;
res.send(`Your city is ${cityName}`);
})
app.listen(port, () => console.log(`Listening on port ${port}`));