This is the backend for a simple blog application built with NestJS, using Prisma as ORM and PostgreSQL as the database. The API is documented with Swagger and supports local development using Docker Compose.
/backend
│── src/
│ ├── posts/ # Posts module (controller, service, DTOs)
│ ├── prisma/ # Prisma service and configuration
│ ├── main.ts # Entry point
│── prisma/ # Prisma migrations and schema
│── .env # Environment variables
│── docker-compose.yml # PostgreSQL setup
git clone https://github.com/plasenca-d/blog-api-nestjs.git
cd blog-api-nestjs
Make sure Docker is installed, then run:
docker-compose up -d
This will start a PostgreSQL database on localhost:5432
.
Copy .env.template to .env and update the DATABASE_URL with your PostgreSQL credentials:
DATABASE_URL="postgresql://bloguser:blogpassword@localhost:5432/blogdb"
Then, run:
npx prisma migrate dev
npm install
npm run start
The API will be available at: http://localhost:3000
Once the backend is running, you can access the API documentation at:
👉 http://localhost:3000/api
This includes endpoints such as:
- GET
/posts
→ Fetch all posts. - GET
/posts/:slug
→ Fetch a single post by slug. - POST
/posts
→ Create a new post.
Create a .env
file and define the following:
DATABASE_URL="postgresql://bloguser:blogpassword@localhost:5432/blogdb"
PORT=3000
- NestJS - Backend framework
- Prisma - ORM for database management
- PostgreSQL - Database
- Docker - Local development environment
- Swagger - API documentation
Feel free to open an issue or a pull request if you’d like to contribute! 🚀
This project is open-source and licensed under the MIT License.