A Node.js backend API with Express, Swagger documentation, and Prisma ORM for Supabase PostgreSQL database.
- 🚀 Express.js server with TypeScript
- 📚 Auto-generated Swagger API documentation at
/docs - 🗄️ Prisma ORM with PostgreSQL (Supabase)
- 🔐 Supabase Authentication integration
- 🔒 Type-safe database operations
- 🎯 RESTful API endpoints
- Node.js 18+
- npm or yarn
- Supabase account and database
-
Install dependencies:
npm install
-
Set up environment variables:
-
Create a
.envfile in the root directory -
Add the following variables:
# Database # Connect to Supabase via connection pooling (for queries) DATABASE_URL="postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-1-eu-west-1.pooler.supabase.com:6543/postgres?pgbouncer=true" # Direct connection to the database (for migrations) DIRECT_URL="postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-1-eu-west-1.pooler.supabase.com:5432/postgres" # Supabase Auth SUPABASE_URL="https://your-project.supabase.co" SUPABASE_ANON_KEY="your-anon-key" SUPABASE_SERVICE_ROLE_KEY="your-service-role-key" # Server PORT=3001 NODE_ENV=development # Frontend FRONTEND_URL="http://localhost:3000" # Seed Admin User (Optional - for customizing the default admin) ADMIN_EMAIL="admin@example.com" ADMIN_PASSWORD="Admin123!" ADMIN_FULL_NAME="Super Admin" ADMIN_ID="00000000-0000-0000-0000-000000000001"
-
-
Generate Prisma Client:
npm run prisma:generate
-
Run database migrations:
npm run prisma:migrate
Or push schema directly (for development):
npm run prisma:push
-
Seed the database with a super admin user:
npm run seed
This will create a default super admin user:
- Email:
admin@example.com(or setADMIN_EMAILin.env) - Password:
Admin123!(or setADMIN_PASSWORDin.env) - Full Name:
Super Admin(or setADMIN_FULL_NAMEin.env) - Role:
super_admin
You can customize these by adding to your
.env:ADMIN_EMAIL="your-admin@example.com" ADMIN_PASSWORD="YourSecurePassword123!" ADMIN_FULL_NAME="Your Name" ADMIN_ID="00000000-0000-0000-0000-000000000001" # Optional: custom UUID
- Email:
-
Start the development server:
npm run dev
Once the server is running, visit:
- Swagger UI: http://localhost:3001/docs
- API Root: http://localhost:3001
- Health Check: http://localhost:3001/health
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm run prisma:generate- Generate Prisma Clientnpm run prisma:migrate- Run database migrationsnpm run prisma:push- Push schema to database (dev only)npm run prisma:studio- Open Prisma Studio (database GUI)npm run seed- Seed database with super admin user
POST /api/auth/login- Login with email and password (uses Supabase Auth)POST /api/auth/logout- Logout userGET /api/auth/me- Get current authenticated user
GET /api/users- Get all usersGET /api/users/:id- Get user by IDPOST /api/users- Create a new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
GET /api/organizations- Get all organizationsGET /api/organizations/my- Get organizations where current user is a memberGET /api/organizations/:id- Get organization by IDPOST /api/organizations- Create a new organization (requires auth)PUT /api/organizations/:id- Update organization (requires auth)DELETE /api/organizations/:id- Delete organization (requires auth)
The Prisma schema includes:
- User - User accounts with:
id- UUID (primary key)email- Unique email addressfullName- Optional full namerole- Optional role (super_adminornull)createdAt- TimestampupdatedAt- Timestamp
modsecurity-back-end/
├── src/
│ ├── lib/
│ │ ├── prisma.ts
│ │ └── supabase.ts
│ ├── routes/
│ │ ├── auth.routes.ts
│ │ └── user.routes.ts
│ └── server.ts
├── prisma/
│ └── schema.prisma
├── .env
├── package.json
├── tsconfig.json
└── README.md
The server runs on port 3001 by default. You can change this in your .env file.
For Supabase configuration:
- DATABASE_URL: Connection pooling URL (port 6543 with
?pgbouncer=true) - used for queries- Find in Supabase project settings under "Database" → "Connection string" → "Connection pooling" → "URI"
- DIRECT_URL: Direct connection URL (port 5432) - used for migrations
- Find in Supabase project settings under "Database" → "Connection string" → "URI" (direct connection)
- SUPABASE_URL: Found in your Supabase project settings under "API" → "Project URL"
- SUPABASE_ANON_KEY: Found in your Supabase project settings under "API" → "Project API keys" → "anon public"
- SUPABASE_SERVICE_ROLE_KEY: Found in your Supabase project settings under "API" → "Project API keys" → "service_role" (secret)
⚠️ Important: Keep this key secure! It has admin privileges and bypasses Row Level Security (RLS)- Used for sending invitation emails and creating users in Supabase Auth
Note: Prisma requires both DATABASE_URL (pooled) and DIRECT_URL (direct) for Supabase. The pooled connection is used for queries, while the direct connection is required for migrations.