A scalable and modular Node.js TypeScript API template for quickly bootstrapping new projects.
- TypeScript for type safety
- Express.js for API routing
- PostgreSQL for database
- Role-based Access Control (RBAC) for permissions management
- JWT Authentication for secure API access
- db-migrate for database migrations
- Winston for logging
- Husky for git hooks
- ESLint and Prettier for code quality
- Mocha & Chai for testing
- Configuration script for easy project setup
- Node.js (v16+)
- npm or yarn
- PostgreSQL
-
Clone this repository
-
Install dependencies:
npm install -
Run the configuration script:
npm run configureThis will guide you through setting up your project name, environment variables, and other configurations.
-
Start the development server:
npm run dev
.
├── migrations/ # Database migrations
├── scripts/ # Utility scripts
├── src/
│ ├── config/ # Application configuration
│ ├── modules/ # Feature modules
│ │ ├── auth/ # Authentication module
│ │ ├── user/ # User module
│ ├── routes/ # API routes
│ ├── shared/ # Shared code
│ └── index.ts # Application entry point
└── tests/ # Test files
The template includes a built-in role-based access control system:
- Users have a role (admin or user)
- Roles have permissions
- API endpoints can be protected with permission requirements
-
Admin: Has all permissions
- CRUD operations on users
- Manage roles and permissions
-
User: Has limited permissions
- Read and update their own profile
You can easily define and assign custom permissions through the permissions API.
The authentication system uses JWT tokens for API access:
- Register:
/api/v1/auth/register - Login:
/api/v1/auth/login - Current User:
/api/v1/auth/me
The following environment variables are required:
APP_NODE_ENV- Node environment (development, test, production)APP_PORT- Port to run the server onAPP_DATABASE_URL- PostgreSQL connection stringAPP_SECRET- Secret key for authentication
See .env.example for all required environment variables.
npm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm test- Run testsnpm run lint- Run ESLintnpm run format- Format code with Prettiernpm run migrate:up- Run database migrationsnpm run migrate:down- Rollback database migrationsnpm run migrate:create <name>- Create a new migrationnpm run configure- Run the project configuration script
This project is licensed under the MIT License.