Nuxt 3 + PostgreSQL
Vue.js meta-framework with PostgreSQL and Prisma.
Overview
Nuxt 3 is a modern Vue.js meta-framework that provides full-stack capabilities with server-side rendering, static site generation, and hybrid deployment options. Built on top of Vue 3 and powered by the Nitro server engine, Nuxt 3 offers automatic imports, file-based routing, and TypeScript support out of the box, making it ideal for building performant web applications with excellent SEO and developer experience.
This stack combines Nuxt 3's versatile rendering capabilities with PostgreSQL's robust relational database features, creating a powerful foundation for data-driven applications. PostgreSQL's ACID compliance, advanced JSON support, and sophisticated query capabilities complement Nuxt 3's server-side rendering and API routes, enabling complex data operations while maintaining excellent performance and data integrity.
Developers building content management systems, e-commerce platforms, or enterprise applications will find this combination particularly valuable. The stack supports everything from simple blogs with relational content structures to complex analytics dashboards leveraging PostgreSQL's window functions and Nuxt 3's reactive data fetching composables.
Key Features
- Hybrid rendering modes with Nuxt 3's routeRules for per-page SSR, SSG, or SPA configuration
- Auto-imported Vue components and composables with zero-configuration setup
- PostgreSQL 16 with advanced JSON/JSONB support for mixed relational and document data
- File-based routing system that automatically generates routes from pages directory structure
- Nitro server engine providing optimized API routes with h3 event handlers
- Built-in TypeScript support with automatic type generation for database schemas
- PostgreSQL's full-text search capabilities with ranking and highlighting for content applications
- Vue 3 Composition API integration with server-side data fetching using useFetch and $fetch
Common Use Cases
- 1Content management systems requiring complex content relationships and full-text search
- 2E-commerce platforms needing ACID-compliant transactions and inventory management
- 3Analytics dashboards leveraging PostgreSQL's window functions and Nuxt 3's reactive charts
- 4Multi-tenant SaaS applications using PostgreSQL's row-level security and Nuxt 3's middleware
- 5Real estate platforms combining PostGIS geospatial queries with Nuxt 3's interactive maps
- 6Enterprise applications requiring audit trails and complex reporting with PostgreSQL's JSON aggregation
- 7Progressive web applications needing offline-first capabilities with PostgreSQL's logical replication
Prerequisites
- Docker and Docker Compose installed with at least 1GB available RAM for PostgreSQL
- Node.js 18+ knowledge for Nuxt 3 development and understanding of Vue 3 Composition API
- Basic SQL knowledge for PostgreSQL schema design and query optimization
- Port 3000 available for Nuxt development server access
- Understanding of environment variables for database connection configuration
- Familiarity with Prisma ORM or similar database toolkit for schema migrations
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 nuxt: 3 build: .4 container_name: nuxt5 environment: 6 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}7 ports: 8 - "3000:3000"9 depends_on: 10 - postgres11 networks: 12 - nuxt-network1314 postgres: 15 image: postgres:16-alpine16 environment: 17 POSTGRES_DB: ${DB_NAME}18 POSTGRES_USER: ${DB_USER}19 POSTGRES_PASSWORD: ${DB_PASSWORD}20 volumes: 21 - postgres_data:/var/lib/postgresql/data22 networks: 23 - nuxt-network2425volumes: 26 postgres_data: 2728networks: 29 nuxt-network: 30 driver: bridge.env Template
.env
1DB_NAME=nuxt2DB_USER=nuxt3DB_PASSWORD=changemeUsage Notes
- 1Docs: https://nuxt.com/docs
- 2Access at http://localhost:3000
- 3Auto-imports: components, composables, utils
- 4File-based routing in pages/
- 5Hybrid SSR/SSG/SPA rendering with routeRules
- 6Nitro server engine, use h3 for API routes
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
nuxt
nuxt:
build: .
container_name: nuxt
environment:
DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
ports:
- "3000:3000"
depends_on:
- postgres
networks:
- nuxt-network
postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- nuxt-network
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 nuxt:5 build: .6 container_name: nuxt7 environment:8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}9 ports:10 - "3000:3000"11 depends_on:12 - postgres13 networks:14 - nuxt-network1516 postgres:17 image: postgres:16-alpine18 environment:19 POSTGRES_DB: ${DB_NAME}20 POSTGRES_USER: ${DB_USER}21 POSTGRES_PASSWORD: ${DB_PASSWORD}22 volumes:23 - postgres_data:/var/lib/postgresql/data24 networks:25 - nuxt-network2627volumes:28 postgres_data:2930networks:31 nuxt-network:32 driver: bridge33EOF3435# 2. Create the .env file36cat > .env << 'EOF'37DB_NAME=nuxt38DB_USER=nuxt39DB_PASSWORD=changeme40EOF4142# 3. Start the services43docker compose up -d4445# 4. View logs46docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/nuxt-postgres/run | bashTroubleshooting
- ECONNREFUSED connecting to postgres:5432: Ensure PostgreSQL container is fully started before Nuxt container attempts connection, add healthcheck or wait script
- Nuxt hydration mismatch errors: Check that server-side data fetching matches client-side state, use process.server checks when accessing browser-only APIs
- PostgreSQL connection pool exhausted: Increase max_connections in postgresql.conf or implement connection pooling with PgBouncer for high-traffic applications
- Prisma schema sync issues: Run prisma db push or prisma migrate deploy in container initialization to ensure database schema matches application expectations
- Nuxt auto-imports not working: Verify components and composables are in correct directories (components/, composables/, utils/) and restart development server
- Memory issues with PostgreSQL: Increase shared_buffers and work_mem settings, or allocate more container memory if handling large datasets
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download