In this lecture, we build a simple Express.js web server and explore how a browser, Node.js and Express work together. We create routes for HTML pages, serve static CSS and image files from the public folder, return JSON data through an API endpoint, and handle 404 and 500 errors.
The lesson examples are available in the tuntiharjoitukset folder. Complete your own Workshop 03 solution in the starter folder and submit it in your own GitHub repository.
Topics
- Node.js, Express.js and localhost
- Starting a server with npm install and npm start
- GET routes with app.get()
- Serving HTML pages with res.sendFile()
- Static files with express.static()
- JSON API endpoint with res.json()
- 404 Not Found and 500 Internal Server Error
- Creating your own GitHub repository from the workshop template