This project is a backend system built using Node.js, Express, Prisma ORM, and PostgreSQL, with additional integrations such as Redis (for caching and queues), Cloudinary (for file uploads), and Nodemailer (for email services).
- User Authentication: Secure login and registration using JWT and bcrypt.
- Email Service: Queued email sending with Nodemailer and BullMQ.
- News Management: CRUD operations for news articles.
- Profile Management: Upload and update user profile pictures via Cloudinary.
- Rate Limiting: API protection using Express Rate Limit.
- Logging: Winston-based logging for error tracking.
- Backend: Node.js, Express
- Database: PostgreSQL (via Prisma ORM)
- Caching & Queue: Redis + BullMQ
- File Uploads: Cloudinary
- Email Service: Nodemailer
- Security: Helmet, CORS, Rate Limiting
- Logging: Winston
/config
├── nodemailer.js # Email transport config
├── queue.js # Redis Queue configuration
├── ratelimit.js # API rate limiting setup
├── redis.config.js # Redis caching setup
/controllers
├── Auth.controller.js # Authentication logic
├── News.controller.js # News CRUD operations
├── Profile.controller.js # Profile management
/db
├── index.js # Prisma client setup
/jobs
├── EmailQueueJob.js # Email job processing using BullMQ
/middlewares
├── auth.middleware.js # JWT authentication middleware
/routes
├── api.routes.js # API routes definition
/utils
├── cloudinary.js # Cloudinary image upload functions
├── logger.js # Winston logger setup
/validations
├── Auth.validation.js # Validation schema for auth
├── News.validation.js # Validation schema for news
.env.example # Environment variable template
index.js # Main server entry point
package.json # Dependencies and scripts
git clone https://github.com/Zenitssuu/postgresSQL-project.git
cd postgresSQL-projectnpm installCreate a .env file in the root directory and fill it with your credentials:
PORT=3000
DATABASE_URL="postgresql://your_user:your_password@localhost:5432/your_db"
JWT_SECRET="your_secret_key"
REDIS_HOST=localhost
REDIS_PORT=6379
CLOUD_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_SECRET=your_cloudinary_secret
EMAIL_SERVICE=your_email_service
EMAIL_HOST=your_smtp_host
EMAIL_PORT=your_smtp_port
EMAIL_USER=your_email
EMAIL_PASS=your_password
EMAIL_FROM=your_from_email
Make sure PostgreSQL is installed and running. Create a database:
psql -U your_user -d postgres
CREATE DATABASE your_db;npx prisma migrate dev --name init
npx prisma generateEnsure Redis is running:
redis-servernpm run devThe server will run on http://localhost:3000
POST /api/auth/register– User registrationPOST /api/auth/login– User login
GET /api/news– Fetch all newsPOST /api/news– Create a news post (requires auth)PUT /api/news/:id– Update a news post (requires auth)DELETE /api/news/:id– Delete a news post (requires auth)
GET /api/auth/send-email?email=user@example.com– Queue an email
GET /api/profile– Get logged-in user profilePUT /api/profile– Update profile picture
- Uses Prisma ORM for interacting with PostgreSQL.
- Implements Redis caching for performance optimization.
- Secure JWT authentication for protected routes.
🚀 Happy Coding!