Express.js - Le routeur (express.Router)

23 Feb 2024 · 9 min
9:11

In this French tutorial, the presenter walks through organizing an Express.js application by extracting route definitions from a monolithic app.js into separate router modules using express.Router. He first reviews basic CRUD routes (GET, POST, PUT, DELETE) defined in a single file, then highlights the scalability problem of keeping all routes together as the app grows. He creates a 'routes' directory with two modules, home.js and client.js, each exporting a Router instance. The tutorial shows how to replace the app instance with a Router in these files, export the router, and import it in app.js. Using app.use, the routers are mounted—home routes at the root and client routes under the '/client' prefix—demonstrating how to remove duplicated prefixes from the client router. The video demonstrates testing each route to confirm functionality and emphasizes that this modular approach makes the main app.js cleaner, easier to maintain, and ready for future expansion (e.g., orders, invoices).

Chapters

More from Yamossoun

8:56
youtube.com

Compteur synchrone - Logique séquentielle

2w ago
11:58
youtube.com

Compteur asynchrone et diviseur de fréquence - Logique séquentielle

3w ago
11:37
youtube.com

Les registres (parallèle et à décalage) - Logique séquentielle

1mo ago
6:14
youtube.com

Bascule T (Toggle) - Logique séquentielle

1mo ago
12:05
youtube.com

Bascule JK - Logique séquentielle

1mo ago
9:17
youtube.com

Bascule D flip-flop active sur front montant - Logique séquentielle

1mo ago
10:08
youtube.com

Bascule D Latch - Logique séquentielle

1mo ago
8:13
youtube.com

Bascule RS - Logique séquentielle

1mo ago
5:04
youtube.com

Logique séquentielle - Introduction

2mo ago
1:15
youtube.com

Le codeur - Logique combinatoire #codeur #logique #circuit #booleanlogic

2mo ago
1:56
youtube.com

Algorithme de calcule de la racine carrée par dichotomie #dichotomy #squareroot #algorithm

3mo ago
See all content