This is an Express API project that uses Prisma ORM to interact with an SQL database. It’s set up to manage data efficiently with an SQL backend.
- ⚙️ Prerequisites
- 📥 Installation
- 🔧 Configuration
- 🗄️ Database Setup
- 📜 Scripts
- 💻 Usage
- 📂 Folder Structure
- 🔗 API Endpoints
- Node.js (v14+)
- Prisma CLI (for database management)
- SQL Database (PostgreSQL, MySQL, SQLite, or compatible with Prisma)
-
Clone the repository:
git clone <repository-url> cd <project-directory>
-
Install dependencies:
npm install
-
Set up your environment variables by creating a
.env
file in the root directory:DATABASE_URL="mysql://USER:PASSWORD@localhost:3306/DATABASE_NAME"
Replace
USER
,PASSWORD
, andDATABASE_NAME
with your SQL credentials. -
Configure the Prisma schema in
prisma/schema.prisma
:datasource db { provider = "mysql" // or your database provider url = env("DATABASE_URL") }
-
Run migrations to set up your database tables:
npx prisma migrate dev --name init
-
Generate Prisma client:
npx prisma generate
-
Optional: Seed your database (if you have a seed script):
npm run seed
npm run dev
– Start the server in development mode with hot reloading.npm run start
– Start the server in production mode.npx prisma studio
– Open Prisma Studio for database management.npx prisma migrate dev
– Create a new migration.npx prisma db push
– Push schema changes directly to the database.
-
Start the server:
npm run dev
-
Use an API client like Postman or Insomnia to interact with the endpoints (examples below).
project-root
├── prisma
│ ├── schema.prisma # Prisma schema file
│ └── migrations # Migration files
├── src
│ ├── controllers # Route controllers
│ ├── routes # API routes
│ ├── middlewares # Middleware functions
│ ├── services # Business logic
│ └── index.js # Server entry point
├── .env # Environment variables
└── package.json # Dependencies and scripts