(Hosted on Railway with CI/CD : ayushwritescode-login-api.up.railway.app/api)
This repository contains the Node.js / NestJS backend for the application. It includes:
- JWT Access/Refresh Token Flow with HTTP-only cookies
- MongoDB for data persistence
- Security Best Practices (HTTP-only cookies, short-lived tokens, server-side validation)
- Rate Limiting to prevent abuse and DDoS attacks
- Protection against XSS & CSRF attacks
- Swagger API Documentation for easy testing and exploration
- Modular Architecture for maintainability
-
HTTP-only Cookies for Refresh Token
Prevents XSS token theft – tokens are never exposed to JavaScript. -
Short-Lived Access Tokens
Minimizes attack window if an access token is compromised. -
Automatic Token Refresh
Uses a refresh token flow and Axios/NestJS interceptors to issue new tokens securely. -
No Tokens in localStorage
Minimizes risk of stolen credentials and XSS attacks. -
Rate Limiting
Protects against brute-force attacks and DDoS by limiting API request rates. -
Cross-Site Scripting (XSS) Prevention
Uses Helmet.js and input validation to sanitize user inputs and prevent script injection. -
Cross-Site Request Forgery (CSRF) Protection
Implements CSRF tokens and SameSite cookie policies to mitigate unauthorized API calls. -
Swagger API Documentation
- Integrated using
@nestjs/swagger - Provides interactive UI at
/apito test endpoints - Helps developers explore and understand API usage easily
- Integrated using
src/auth/: Auth features: JWT strategies, guards, controllers for login, signup, refresh and access token generation.src/user/: User featuresmain.ts: NestJs entry point
- Node.js v16+
- npm or yarn
- MongoDB installed locally (or Docker-based)
.envfile with environment variables (JWT secrets, etc.)
git clone https://github.com/<your-org>/easygenerator-backend.git
cd easygenerator-backendnpm install
# or
yarn installIn the project root:
PORT=3000
MONGO_URI=mongodb://mongodb:27017/easygeneratordb
JWT_ACCESS_EXPIRES=15s
JWT_REFRESH_EXPIRES=7d
JWT_ACCESS_SECRET=easygeneratorsecret
JWT_REFRESH_SECRET=easygeneratorrefreshsecret
Adjust as needed. ** Please modify the cors configuration in main.ts as required.
4. Run Locally [Recommended approach: docker compose up] (Development) [Check Mongo DB connection string if running without docker]
npm run start:dev
# or
yarn start:devNestJS dev server runs at http://localhost:3000.
Once the server is running, open:
http://localhost:3000/api
This interactive documentation allows you to explore available endpoints and test them directly from the UI.
npm run build
npm run start:prodCompiles TypeScript into dist/ and runs with Node in production mode.
If desired, you can run everything in Docker. Example:
docker-compose build
docker-compose up -dThis spins up MongoDB + Backend together. The backend will listen on port 3000.
- Node.js v16+
- npm or yarn
- MongoDB (local or Docker)
- Docker (optional, for containerized deployment)
- Fork the repository
- Create a branch:
git checkout -b feature/my-feature - Commit changes:
git commit -m 'Add some feature' - Push to GitHub:
git push origin feature/my-feature - Open a Pull Request
MIT © 2025 ayushwritescode
