-
Notifications
You must be signed in to change notification settings - Fork 3
[Backend] NodeJS - week 1 #146
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
Draft
marcorichetta
wants to merge
16
commits into
main
Choose a base branch
from
58-create-backend-nodejs-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0a99c40
move legacy nodejs week 2 to backend nodejs week1
marcorichetta cef7825
follow new modules naming
marcorichetta 94e6b26
move legacy nodejs week3 to backend nodejs week2
marcorichetta 47351d0
chore: refreshed links removed stale code
magdazelena 0fe5ace
chore: scaffold teacher materials
magdazelena 76d2984
chore: add info about parameters
magdazelena a3187a2
chore: add route order example
magdazelena 4bd0fac
Update courses/backend/node/week1/assignment.md
magdazelena 887a414
Update courses/backend/node/week1/session-materials/01-server.md
magdazelena c60a940
Update courses/backend/node/week1/session-materials/02-schema.md
magdazelena b2175a2
chore: add middleware code
magdazelena c5c14e6
chore: move week2 to a separate PR
magdazelena 2f96c60
chore: translated sql to sqlite
magdazelena d1ecddc
chore: reorder content
magdazelena 6cca8f8
chore: remove items from readme, refresh prep links
magdazelena b71c754
chore: update links
magdazelena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
# Node | ||
# Node.js | ||
|
||
Coming soon | ||
This module is part of the Backend specialism and focuses on using Node.js to build backend services, APIs, and databases. It builds on the Introduction to Backend module from Foundation with more advanced tooling, patterns, and responsibilities. | ||
|
||
## Contents | ||
|
||
| Week | Topic | Preparation | Lesson Plan | Assignment | | ||
| ---- | ------------------------ | ----------------------------------- | ----------------------------------- | ------------------------------------- | | ||
| 1. | Express | [Preparation](week1/preparation.md) | [Assignment](./week1/assignment.md) | [Session plan](week1/session-plan.md) | | ||
| 2. | Database connection; API | [Preparation](week2/preparation.md) | [Assignment](./week1/assignment.md) | [Session plan](week2/session-plan.md) | | ||
|
||
## Module Learning Goals | ||
|
||
By the end of this module, you will be able to: | ||
|
||
- [ ] Build web servers with Express.js | ||
- [ ] Design and implement APIs using HTTP methods following REST principles | ||
- [ ] Use middlewares for authentication, logging, and validation | ||
- [ ] Test APIs using Postman | ||
- [ ] Use logging and debugging tools to monitor and troubleshoot applications | ||
- [ ] Connect to databases and implement CRUD operations |
15 changes: 15 additions & 0 deletions
15
courses/backend/node/module-materials/examples/middleware.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import express from "express"; | ||
const app = express(); | ||
|
||
app.use((req, _res, next) => { | ||
console.log(req.headers["accept-language"]); | ||
const isFromDenmark = req.headers["accept-language"].includes("da"); | ||
console.log(isFromDenmark); | ||
req.isFromDenmark = isFromDenmark; | ||
|
||
next(); | ||
}); | ||
|
||
app.listen(3000, function () { | ||
console.log(`> Ready on http://localhost:3000`); | ||
}); |
20 changes: 20 additions & 0 deletions
20
courses/backend/node/module-materials/examples/parameters.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import express from "express"; | ||
const app = express(); | ||
|
||
// query parameters | ||
// http://localhost:3000/query-parameters?hej=23,%20sd-p | ||
app.get("/query-parameters", (req, res) => { | ||
console.log(req.query); | ||
res.send({ data: req.query }); | ||
}); | ||
|
||
// URL parameters | ||
// http://localhost:3000/parameters/apple-eater | ||
app.get("/parameters/:username", (req, res) => { | ||
console.log(req.params); | ||
res.send({ data: req.params }); | ||
}); | ||
|
||
app.listen(3000, function () { | ||
console.log(`> Ready on http://localhost:3000`); | ||
}); |
26 changes: 26 additions & 0 deletions
26
courses/backend/node/module-materials/examples/route-order.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import express from "express"; | ||
const app = express(); | ||
|
||
app.get("/data", (_req, res) => { | ||
res.send({ data: 1 }); | ||
}); | ||
|
||
app.get("/data", (_req, res) => { | ||
res.send({ data: 2 }); | ||
}); | ||
|
||
////// which one is being called when? | ||
|
||
app.get("/data/:id", (req, res) => { | ||
console.log("Parametrized URL"); | ||
res.send({ data: req.params }); | ||
}); | ||
|
||
app.get("/data/overview", (req, res) => { | ||
console.log("Overview"); | ||
res.send({ data: req.params }); | ||
}); | ||
|
||
app.listen(3000, function () { | ||
console.log(`> Ready on http://localhost:3000`); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import express from "express"; | ||
const router = express.Router(); | ||
|
||
router.get("/", async (_request, response) => { | ||
response.send({ data: "from app.use" }); | ||
}); | ||
|
||
export default router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import express from "express"; | ||
import router from "./examples/router.js"; | ||
|
||
const app = express(); | ||
|
||
app.get("/", (_req, res) => { | ||
res.send({ data: "from app.get" }); | ||
}); | ||
|
||
app.use("/use", router); | ||
|
||
app.listen(3000, function () { | ||
console.log(`> Ready on http://localhost:3000`); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.