How zenika/cours-services-web-avec-nodejs works
Project type and purpose
• This is a progressive Node.js training project that starts as a CLI tool for managing contacts in a JSON file, evolves into an HTTP-based micro-service with Express, adds an HTTP client, and finally a minimal web UI.
• Its purpose is to teach: Node.js core, asynchronous programming, command-line interfaces (commander.js), file persistence (contacts.json), HTTP servers (Express + body-parser), HTTP clients (request), and static file serving (serve-static).
File structure
• Top-level files:
• app.js – main entry point for both CLI and server.
• contacts.json – simple JSON store of contacts.
• package.json / .npmrc – project configuration and dependencies.
• tests/ – test suite driving each step (step0 to step6, test-utils).
• No subdirectories beyond tests; all logic lives under app.js (and any modules you add).
• The progression implies three runtime modes:
• CLI mode reading/writing contacts.json directly.
• “serve” mode launching Express HTTP server.
• “HTTP client” mode where CLI commands issue HTTP requests.
• Tests invoke app.js with different flags (--memory, serve, add, remove, etc.).
README for additional insights
• The README outlines each TP step, required commands, libraries (commander.js, shortid, Express, body-parser, request, serve-static).
• It specifies API routes (/health, /contacts, /contacts/:id) and CLI commands (list, add, remove, serve, update).
• It suggests an optional in-memory vs. file-based persistence switch.
Elements
• From CLI App to Contacts Store (file I/O).
• From CLI App to Express Server (HTTP requests).
• From Web UI to Express Server (HTTP requests).
• From Express Server to Contacts Store.
• From Test Suite to both CLI App and Express Server.
• Rectangles for runtime components (CLI, Server, UI).
2. In Presentation: place “CLI App” and “Web UI”.
3. In Application: place “Express Server (app.js + routing)”.
• CLI App → Persistence (direct mode)
• CLI App → Express Server (HTTP mode)
• Express Server → Persistence
• Web UI → Express Server
• Test Suite → CLI App & Test Suite → Express Server
7. Technologies next to each component: e.g., “Express + body-parser”, “commander.js”, “request”, “shortid”, “serve-static”.
• Core modules vs. third-party libraries
• File vs. memory storage
• Synchronous vs. asynchronous I/O