A RESTful API backend built with Express.js, Prisma ORM, and PostgreSQL featuring user authentication.
- User authentication (signup, login, logout) with JWT
- Password hashing with bcrypt
- Health check endpoint
- PostgreSQL database with Prisma ORM
- Graceful shutdown handling
- Runtime: Node.js (ES Modules)
- Framework: Express.js 5
- Database: PostgreSQL
- ORM: Prisma 7
- Authentication: JWT (jsonwebtoken)
- Password Hashing: bcryptjs
- Environment: dotenv
├── prisma/
│ ├── schema.prisma # Database schema
│ └── migrations/ # Database migrations
├── src/
│ ├── server.js # Application entry point
│ ├── config/
│ │ └── db.js # Database connection
│ ├── controllers/
│ │ └── authController.js
│ ├── routes/
│ │ └── authRoutes.js
│ └── utils/
│ └── generateToken.js
├── package.json
└── prisma.config.ts
- Node.js (v18 or higher recommended)
- PostgreSQL database
- npm or yarn
-
Clone the repository
git clone <repository-url> cd express-js
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
-
Configure your
.envfile (see Environment Variables section) -
Generate Prisma client
npx prisma generate
-
Run database migrations
npx prisma migrate dev
-
Start the development server
npm run dev
Create a .env file in the root directory:
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
JWT_SECRET="your-jwt-secret-key"- User - User accounts with authentication (id, name, email, password, createdAt)
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Check server status |
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/signup |
Register a new user |
| POST | /auth/login |
Login user |
| POST | /auth/logout |
Logout user |
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm test |
Run tests |
# Generate Prisma client
npx prisma generate
# Run migrations
npx prisma migrate dev
# Open Prisma Studio
npx prisma studio
# Reset database
npx prisma migrate resetThe server runs on port 5001 by default.
npm run devServer URL: http://localhost:5001
ISC
Farhan