A robust RESTful API built with Node.js, Express, and PostgreSQL, designed to power a developer blog platform. This backend service handles user authentication, blog post management (including image uploads via Cloudinary), and categorization.
📱 Mobile Client: The companion mobile application for this backend can be found here: OnoPUNPUN/devblogs
- User Authentication: Secure registration and login using JWT (JSON Web Tokens) and bcrypt password hashing.
- Blog Post Management: Create, read, and list blog posts.
- Image Uploads: Seamless integration with Cloudinary for handling blog post cover images.
- Categorization: Categorize blog posts for better content organization.
- Database ORM: Prisma ORM for type-safe database interactions and migrations.
- Dockerized: Fully containerized using Docker and Docker Compose for easy setup and deployment.
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL
- ORM: Prisma
- Authentication: jsonwebtoken, bcryptjs
- File Uploads: Multer, Cloudinary
- Containerization: Docker, Docker Compose
Before you begin, ensure you have the following installed on your machine:
- Node.js
- Docker and Docker Compose
- A Cloudinary account for image uploads
Create a .env file in the root directory and configure the following variables:
# Server
PORT=5003
NODE_ENV=development
# Database (Required for local development without Docker)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/devblog?schema=public"
# JWT Secret
JWT_SECRET=your_super_secret_jwt_key
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret(Note: When running with Docker Compose, the DATABASE_URL is automatically configured to point to the Postgres container).
The easiest way to get the project running is using Docker. This will spin up both the Node.js application and the PostgreSQL database.
- Ensure Docker is running.
- Build and start the containers:
docker-compose up --build
- The API will be available at
http://localhost:5003.
- Install dependencies:
npm install
- Start a local PostgreSQL instance and update the
DATABASE_URLin your.envfile. - Push the Prisma schema to your database:
npx prisma db push
- Start the development server:
npm run dev
GET /- Returns API status.
POST /auth/register- Register a new user.- Body:
{ "username": "test", "email": "test@test.com", "password": "pwd" }
- Body:
POST /auth/login- Authenticate user and receive JWT.- Body:
{ "email": "test@test.com", "password": "pwd" }
- Body:
Note: All blog endpoints require a valid JWT token in the Authorization header (Bearer <token>).
GET /blogs- Get a list of all blogs.GET /blogs/:id- Get a specific blog by ID.POST /blogs- Create a new blog post. (Acceptsmultipart/form-data)- Fields:
title,content,categoryIds - File:
image(Blog cover image)
- Fields:
GET /categories- Get all available categories.
The database consists of three main models:
- User: Stores user credentials and relates to authored blogs.
- Blog: Stores blog content, image URLs, and relates to an Author and Categories.
- Category: Stores blog categories for filtering and organization.
Check prisma/schema.prisma for the complete schema definition.
This project is licensed under the ISC License.