A comprehensive REST API built with TypeScript and Express.js for home inventory management with JWT authentication.
- TypeScript for type safety
- Express.js for the web framework
- JWT Authentication with token-based security
- Prisma ORM with PostgreSQL database
- Swagger/OpenAPI documentation
- Zod for request validation
- Rate Limiting for API protection
- CORS and Helmet for security
- Morgan for logging
- bcrypt for password hashing
- ✅ JWT token-based authentication
- ✅ Password hashing with bcrypt
- ✅ Rate limiting (100 req/15min general, 5 req/15min auth)
- ✅ Input validation and sanitization
- ✅ CORS and Helmet security headers
- ✅ Protected routes requiring authentication
- ✅ SQL injection protection via Prisma ORM
- Node.js (v18 or higher)
- PostgreSQL database
- npm or yarn
-
Install dependencies:
npm install
-
Set up environment variables:
copy .env.example .env
Edit
.envfile with your configuration (seeENV_VARS.mdfor details):DATABASE_URL="postgresql://username:password@localhost:5432/preben_prepper" JWT_SECRET="your-super-secure-jwt-secret-key" JWT_EXPIRES_IN="7d" PORT=3000
-
Set up the database:
npm run db
-
Start development server:
npm run dev
-
View API documentation: Open http://localhost:3000/api-docs
npm run dev- Start development server with hot reloadnpm run build- Build the TypeScript codenpm start- Start production servernpm run type-check- Run TypeScript type checking
GET /api/health- Check API health status
GET /api/users- Get all usersGET /api/users/:id- Get user by IDPOST /api/users- Create new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
GET /api/inventory- Get all inventory itemsGET /api/inventory/:id- Get inventory item by IDPOST /api/inventory- Create new inventory itemPUT /api/inventory/:id- Update inventory itemDELETE /api/inventory/:id- Delete inventory item
Note: Multiple inventory items can have the same name, allowing you to track different batches or expiration dates of the same product.
src/
├── config/ # Configuration files
│ └── swagger.ts # Swagger/OpenAPI setup
├── middleware/ # Express middleware
│ ├── errorHandler.ts
│ ├── notFoundHandler.ts
│ └── validation.ts
├── routes/ # API route handlers
│ ├── health.ts
│ └── users.ts
├── schemas/ # Zod validation schemas
│ └── user.ts
└── index.ts # Application entry point
PORT- Server port (default: 3000)NODE_ENV- Environment (development/production)DATABASE_URL- PostgreSQL connection string (for Prisma)
- Set up PostgreSQL database
- Configure Prisma schema
- Add authentication middleware
- Add rate limiting
- Add comprehensive logging
- Add tests