Skip to content
Draft
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
22 changes: 20 additions & 2 deletions courses/backend/node/README.md
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 courses/backend/node/module-materials/examples/middleware.js
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 courses/backend/node/module-materials/examples/parameters.js
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 courses/backend/node/module-materials/examples/route-order.js
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?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
////// which one is being called when?
// 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`);
});
8 changes: 8 additions & 0 deletions courses/backend/node/module-materials/examples/router.js
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;
14 changes: 14 additions & 0 deletions courses/backend/node/module-materials/index.js
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`);
});
Loading