DevPulse is a TypeScript-based Express API for basic issue tracking with user authentication and role-based access control.
- User signup and login with JWT authentication
- Issue creation, retrieval, updates, and deletion
- PostgreSQL database using
pg - Role-based access control for protected routes
- Error handling middleware
- Node.js
- TypeScript
- Express
- PostgreSQL
pgjsonwebtokenbcryptjsdotenvtsup
src/app.ts- main Express application and routingsrc/server.ts- HTTP server startup and database initializationsrc/app/modules/auth- authentication controllers and routessrc/app/modules/issues- issue controllers and routessrc/app/middleware- authentication and error handling middlewaresrc/db/index.ts- PostgreSQL connection and table creationsrc/app/config/index.ts- environment config loader
-
Install dependencies:
npm install
-
Create a
.envfile in the project root with the following variables:PORT=5000 CONNECTIONSTRING=postgresql://user:password@host:port/database SECRET_KEY=your_jwt_secret
-
Run the app in development mode:
npm run dev
-
Build for production:
npm run build
-
Start the built app:
npm start
PORT- port where the server listensCONNECTIONSTRING- PostgreSQL connection stringSECRET_KEY- secret key for JWT signing
npm run dev- run the server withtsxin watch modenpm run build- compile TypeScript withtsupnpm start- run the compiled production server
-
POST /api/auth/signup- Request body:
{ name, email, password, role? } - Creates a user and returns user data
- Request body:
-
POST /api/auth/login- Request body:
{ email, password } - Returns JWT token and user info
- Request body:
-
POST /api/issues- Protected route
- Required header:
Authorization: <token> - Request body:
{ title, description, type?, status?, reporter_id }
-
GET /api/issues- Public route
- Returns all issues
-
GET /api/issues/:id- Public route
- Returns a single issue by ID
-
PATCH /api/issues/:id- Protected route
- Required header:
Authorization: <token> - Updates issue fields
-
DELETE /api/issues/:id- Protected route
- Required header:
Authorization: <token> - Only users with the
maintainerrole can delete issues
- The database tables are created automatically at startup if they do not already exist.
- User roles default to
contributorwhen not provided. - The
DELETE /api/issues/:idroute is restricted withroleCheck("maintainer").
- If the server fails to start, verify the database connection string and that PostgreSQL is running.
- If JWT authentication fails, make sure
SECRET_KEYmatches the key used in your application.