Skip to content

A comprehensive Node.js backend starter template with Express.js, PostgreSQL, Prisma ORM, JWT authentication, file upload, and more

Notifications You must be signed in to change notification settings

ibnabdullah1/nodejs-express-prisma-starter

Repository files navigation

Node.js Express Prisma Starter Template

A comprehensive, production-ready Node.js backend starter template built with Express.js, PostgreSQL, Prisma ORM, TypeScript, and modern development practices.

πŸš€ Features

  • πŸ”§ Modern Stack: Node.js, Express.js, TypeScript, PostgreSQL, Prisma ORM
  • πŸ” Authentication: JWT-based authentication with refresh tokens
  • πŸ‘₯ User Management: Complete user CRUD with role-based access control
  • πŸ“ File Upload: Cloudinary integration for media management
  • πŸ“§ Email Service: Nodemailer integration for email functionality
  • πŸ›‘οΈ Security: Helmet, CORS, rate limiting, input validation
  • πŸ“Š Database: PostgreSQL with Prisma ORM for type-safe operations
  • πŸ§ͺ Testing: Jest setup with coverage reporting
  • πŸ“ Code Quality: ESLint, Prettier, Husky for code standards
  • 🐳 Docker: Complete Docker setup with docker-compose
  • πŸ“š Documentation: Comprehensive documentation and API reference
  • πŸ”„ CI/CD Ready: GitHub Actions workflow templates

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn package manager
  • PostgreSQL database
  • Git

⚑ Quick Start

1. Clone the Repository

git clone <your-repository-url>
cd nodejs-express-prisma-starter

2. Install Dependencies

npm install

3. Environment Setup

# Copy environment template
cp env.example .env

# Edit .env with your configuration
nano .env

4. Database Setup

# Generate Prisma client
npm run db:generate

# Run database migrations
npm run migrate

# (Optional) Seed the database
npm run db:seed

5. Start Development Server

npm run dev

Your server will be running at http://localhost:5000

πŸ› οΈ Available Scripts

Development

  • npm run dev - Start development server with hot reload
  • npm run build - Build the project for production
  • npm run start - Start production server

Database

  • npm run migrate - Run database migrations
  • npm run migrate:deploy - Deploy migrations to production
  • npm run migrate:reset - Reset database
  • npm run db:studio - Open Prisma Studio
  • npm run db:generate - Generate Prisma client
  • npm run db:seed - Seed database with sample data

Code Quality

  • npm run lint - Run ESLint
  • npm run lint:fix - Fix ESLint errors
  • npm run format - Format code with Prettier
  • npm run type-check - Run TypeScript type checking

Testing

  • npm test - Run tests
  • npm run test:watch - Run tests in watch mode
  • npm run test:coverage - Run tests with coverage

Docker

  • npm run docker:build - Build Docker image
  • npm run docker:run - Run Docker container
  • npm run docker:compose - Start with docker-compose

πŸ“ Project Structure

src/
β”œβ”€β”€ controllers/         # Request handlers
β”œβ”€β”€ services/           # Business logic
β”œβ”€β”€ models/             # Data models
β”œβ”€β”€ middleware/         # Express middleware
β”œβ”€β”€ utils/              # Utility functions
β”œβ”€β”€ types/              # TypeScript type definitions
β”œβ”€β”€ constants/          # Application constants
β”œβ”€β”€ validators/         # Request validation schemas
β”œβ”€β”€ database/           # Database configuration
β”œβ”€β”€ routes/             # Route definitions
β”œβ”€β”€ config/             # Configuration files
β”œβ”€β”€ scripts/            # Utility scripts
β”œβ”€β”€ templates/          # Email templates
β”œβ”€β”€ tests/              # Test files
β”œβ”€β”€ app.ts              # Express app configuration
└── server.ts           # Server entry point

πŸ”§ Configuration

Environment Variables

See env.example for all available environment variables:

  • Database: PostgreSQL connection string
  • JWT: Authentication secrets and expiration times
  • Email: SMTP configuration for email sending
  • Cloudinary: File upload and storage
  • Security: CORS, rate limiting, and other security settings

Database Schema

The template includes the following models:

  • User: User authentication and profile management
  • Media: File upload and metadata storage

πŸš€ Deployment

Docker Deployment

# Build and start with docker-compose
npm run docker:compose

# Or build and run manually
npm run docker:build
npm run docker:run

Manual Deployment

  1. Build the application:

    npm run build
  2. Set up production environment:

    cp env.example .env
    # Configure production environment variables
  3. Run database migrations:

    npm run migrate:deploy
  4. Start the application:

    npm start

πŸ“š Documentation

Comprehensive documentation is available in the DOCS/ directory:

πŸ§ͺ Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

πŸ” Code Quality

The project includes:

  • ESLint for code linting
  • Prettier for code formatting
  • Husky for git hooks
  • lint-staged for pre-commit checks

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

See Contributing Guide for detailed information.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

  • Documentation: Check the DOCS/ directory
  • Issues: Create an issue on GitHub
  • Discussions: Use GitHub Discussions for questions

πŸ™ Acknowledgments


Happy Coding! πŸŽ‰

About

A comprehensive Node.js backend starter template with Express.js, PostgreSQL, Prisma ORM, JWT authentication, file upload, and more

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published