This project template provides a Node.js TypeScript setup with Express, Prisma, and jsonwebtoken (JWT) for authentication. It includes an out-of-the-box CRUD setup and allows the generation of additional routes, controllers, and services for new database tables.
To start a new project using this template, run:
npx nodejs-typescript-express-prisma
Upon initialization, you will be prompted to provide specific project configurations:
-
Roles: Specify any custom roles you'd like to add, in addition to the default
ADMIN
role already configured in the schema. List roles in a comma-separated format, e.g.,ROLE1,ROLE2,...
. -
Environment Variables: You will be prompted to set up the following environment variables:
NODE_ENV
: Environment (development/production)PORT
: The port number to run the Express serverJWT_SECRET
: Secret key for JWT-based authentication (auto-generated)DB_STRING
: PostgreSQL connection URI for PrismaHOST
: The root URL for the APISMTP_HOST
: SMTP server host for emailSMTP_PORT
: SMTP server portSMTP_USER
: SMTP usernameSMTP_PASS
: SMTP passwordCORS_ORIGIN
: Allowed CORS originsAPI_RATE_LIMIT
: Rate limiting per minute
- ✨ Interactive CLI for CRUD operations
- 🔒 JWT Authentication with role-based access
- 📝 OpenAPI/Swagger documentation
- 🚀 TypeScript support
- 🗄️ Prisma ORM with PostgreSQL
- ✅ Input validation with Joi
- 🔍 Error handling middleware
- 📧 Email integration
- 🔄 API rate limiting
- 🌐 CORS support
- 📊 API monitoring
yarn crud:generate
This interactive tool will guide you through:
- Entity name selection
- Field definitions with types
- Generation of:
- Controller with OpenAPI docs
- Service layer
- Routes
- Validation schemas
- TypeScript interfaces
yarn crud:delete
This will:
- Show existing modules
- Remove selected files
- Clean up routes
- Update documentation
string
: String data typeint
: Integer data typedate
: Date with timestampdouble
: Double/Float data typeboolean
: Boolean data typeid
: UUID primary keyfid
: UUID foreign keyarray
: JSON arrayobject
: JSON objecttext
: Text data type
Documentation is automatically generated and available at:
- Interactive UI:
http://localhost:3000/api-docs
- Raw OpenAPI spec:
http://localhost:3000/api-docs.json
model User {
id String @id @default(cuid())
name String? @db.VarChar(255)
password String? @db.VarChar(255)
email String? @unique @db.VarChar(255)
phoneNumber String? @default("0600000000") @map("phone_number") @db.VarChar(255)
role UserRolesEnum? @default(ADMIN)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@map("users")
}
enum UserRolesEnum {
ADMIN
}
src/
├── config/ # Configuration files
├── controllers/ # Route controllers
├── docs/ # API documentation
│ ├── swagger.ts # Swagger configuration
│ └── *.yml # API specifications
├── middlewares/ # Custom middlewares
├── routes/ # API routes
├── services/ # Business logic
├── utils/ # Utility functions
└── index.ts # Application entry point
{
"scripts": {
"dev": "nodemon -r tsconfig-paths/register src/index.ts",
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
"start": "node dist/index.js",
"crud:generate": "ts-node ./scripts/crud-creation.ts",
"crud:delete": "ts-node ./scripts/crud-deletion.ts",
"init:prisma": "ts-node ./scripts/init-prisma.ts",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev",
"prisma:studio": "prisma studio"
}
}
- Node.js v18 or higher
- PostgreSQL
- Yarn or npm