This project is for trying out NestJS.
Please note this was created on a windows PC, while running on WSL2. Keep that in mind if you run into any issues.
This demo assumes you've already setup your development environment following the prisma demo repo (node, npm, etc). You will need at least Node 20+ to run this project.
One additional requirement is the NestJS CLI. If you don't have it installed, you can do so via npm:
npm install -g @nestjs/cliFirst, install the dependencies:
npm installThen, start the development server:
npm run start:devAccess the application at http://localhost:3000.
Generate a new module:
nest generate module some-module-name
nest generate service some-module-name
nest generate controller some-module-name- Complete the books module (CRUD operations).
- Support a publishers module (a book has a single publisher).
- Support a genres module (a book can have multiple genres). NOTE: be careful how you handle this to avoid duplicating data - you only want to store either books inside genres, or genres inside books, not both. NOTE Number 2: this isn't ideal and you wouldn't have to do this with a real database, this is just for the purpose of this demo.
Bonus Points: add a query param to the books GET endpoint called includeAuthor which when set to true will include the author details in the response. So a request to /books?includeAuthor=true would return something like:
[
{
"id": 1,
"title": "Book Title",
"author": {
"id": 1,
"name": "Author Name"
}
}
]Hint: you'll need to make use of the @Query decorator, I've already injected the AuthorsService into the BooksService for you to make this easier.
Extra Bonus Points: use pipes to validate id params as integers More Extra Bonus Points: add swagger to your endpoints - see here for more info