0
0
NestJSframework~30 mins

NestJS vs Express vs Fastify comparison - Hands-On Comparison

Choose your learning style9 modes available
Build a Simple API with NestJS, Express, and Fastify
📖 Scenario: You are creating a simple API to manage a list of books for a small library. You want to understand how to set up this API using three popular Node.js frameworks: NestJS, Express, and Fastify. This will help you see the differences in setup and structure.
🎯 Goal: Build a basic API endpoint /books that returns a list of books using NestJS, Express, and Fastify. You will create the data, configure the server, implement the route, and complete the setup for each framework.
📋 What You'll Learn
Create a list of books with exact titles and authors
Set up a configuration variable for the server port
Implement a GET route /books that returns the book list
Complete the server start code for each framework
💡 Why This Matters
🌍 Real World
APIs like this are common in web apps to provide data to frontend clients or other services.
💼 Career
Understanding how to set up routes and servers in popular Node.js frameworks is essential for backend development roles.
Progress0 / 4 steps
1
Create the books data list
Create a constant array called books with these exact objects: { title: 'The Hobbit', author: 'J.R.R. Tolkien' }, { title: '1984', author: 'George Orwell' }, and { title: 'To Kill a Mockingbird', author: 'Harper Lee' }.
NestJS
Need a hint?

Use const books = [ ... ] with objects inside.

2
Set the server port configuration
Create a constant called PORT and set it to 3000.
NestJS
Need a hint?

Use const PORT = 3000; to set the port number.

3
Implement the GET /books route
Use app.get('/books', (req, res) => { res.json(books); }) to create a route that returns the books array as JSON.
NestJS
Need a hint?

Use app.get('/books', (req, res) => { res.json(books); }).

4
Start the server listening on the port
Add app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }); to start the Express server.
NestJS
Need a hint?

Use app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); }).