rv-exp
v1.0.3
Published
CLI tool to scaffold a modular Express.js app with role-based auth and Sequelize/Postgres setup.
Maintainers
Readme
RUN
npx rv-exp my-app
CLI tool to scaffold a modular Express.js app with role-based auth and Sequelize/Postgres setup.
Created by https://github.com/aravindh99 ❤️
Getting Started
npx create-rv-express my-app cd my-app npm install
configure your environment variables in a .env file:
Server
PORT=5000 NODE_ENV=development
Database (used by Sequelize and Docker)
DB_USER=postgres DB_PASSWORD=your-password DB_NAME=your-db-name DB_HOST=localhost DB_PORT=5432
Full DB URI (used in db.js)
DB_URI=postgres://postgres:your-password@localhost:5432/your-db-name
Authentication
JWT_SECRET=your-secret-key
docker
docker compose up -d
This will start a Postgres container using the values from .env.
Running the App
npm run dev
backend-temp/ │ .gitignore │ docker-compose.yml │ package.json │ readme.md │ server.js │ └───src ├───config │ db.js # Sequelize connection setup │ ├───models │ initModels.js # Associations between models │ ├───modules │ ├───auth │ │ auth.controller.js # Auth controller logic │ │ auth.routes.js # Auth routes (login, etc.) │ │ auth.schema.js # Zod schema for validation │ │ │ └───users │ user.model.js # User model definition │ └───shared │ appError.js # Custom error class │ asyncHandler.js # Async wrapper for controllers │ errorHandler.js # Global error handler │ ├───middlewares │ auth.js # JWT protect middleware │ role.js # Role-based access control │ validate.js # Request validation middleware │ └───utils pagination.js # Utility for limit/offset pagination
Middlewares & Utilities
auth.js
Protects routes by verifying JWT tokens. Attaches the authenticated user to req.user.
role.js
Restricts access to specific roles (super_admin, user, etc.).
Usage:
router.get("/admin", protect, allowRoles("super_admin"), handler);
validate.js
Validates request bodies using Zod schemas.
Usage:
router.post("/login", validate(loginSchema), login);
asyncHandler.js
Wraps async controllers to avoid repetitive try/catch.
appError.js
Custom error class with statusCode, status, and isOperational.
errorHandler.js
Global error handler that formats error responses and logs unexpected issues.
pagination.js
Utility to parse limit and offset from query params with safe defaults.
