A boilerplate project for building a REST API with Express, TypeScript, and JWT authentication.
- 🚀 Express.js for building REST APIs\
- 🔐 JWT (JSON Web Tokens) for authentication & authorization\
- 📝 TypeScript with type safety\
- ⚡ Middleware for request validation\
- 🗂️ Project structure for scalability
git clone https://github.com/your-username/express-jwt-typescript.git
cd express-jwt-typescriptnpm installCreate a .env file in the root of the project:
PORT=5000
JWT_SECRET=your_secret_key
TOKEN_EXPIRES_IN=1hnpm run devnpm run build
npm startsrc/
├── controllers/ # Route handlers
├── middlewares/ # Auth & error middlewares
├── routes/ # API routes
├── services/ # Business logic
├── types/ # TypeScript types
├── utils/ # Helper functions
├── index.ts # App entry point
POST /api/auth/register
Content-Type: application/json
{
"username": "testuser",
"password": "password123"
}POST /api/auth/login
Content-Type: application/json
{
"username": "testuser",
"password": "password123"
}Response:
{
"token": "your_jwt_token"
}GET /api/profile
Authorization: Bearer <token>npm run dev→ Run in dev mode with nodemon & ts-node\npm run build→ Build TypeScript into JavaScript (dist/)\npm start→ Run compiled JavaScript in production
MIT © Sahil Shrestha