A Node.js backend server built with Express, TypeScript, MongoDB, Redis, Google Cloud Storage, and more.
- Backend
- User registration, login, and Google OAuth
- Email verification and password reset via OTP
- JWT-based authentication and session management
- File/media upload to Google Cloud Storage
- Logging (Winston, Morgan) and audit logs
- Modular route and service structure
- Redis for queues, OTP, and socket.io adapter
- TypeScript for type safety
- Node.js (v18+ recommended)
- Yarn or npm
- MongoDB (local or remote)
- Redis (local or remote)
- Google Cloud account (for Storage)
- SMTP credentials (for email sending)
git clone <repo-url>
cd backendyarn install
# or
npm installCopy .env.example to .env and fill in the required values:
cp .env.example .envRequired fields:
PORT- Port to run the serverDB_HOST,DB_PORT,DB_USER,DB_PASSWORD,DB_NAME- MongoDB connectionJWT_SECRET- Secret for JWT signingANDROID_CLIENT_ID,IOS_CLIENT_ID,WEB_CLIENT_ID- Google OAuth client IDsSMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASS,SMTP_FROM_USER- SMTP configREDIS_HOST,REDIS_PORT,REDIS_PASSWORD,REDIS_URL- Redis configGOOGLE_CLOUD_PROJECT_ID,GOOGLE_CLOUD_BUCKET_NAME- Google Cloud Storage
Do not commit your .env file.
- Create a Google Cloud project and enable Storage.
- Create a service account with Storage permissions.
- Download the service account key as
google-cloud-key.jsonand place it in the project root. - Set
GOOGLE_CLOUD_PROJECT_IDandGOOGLE_CLOUD_BUCKET_NAMEin.env.
Do not commit google-cloud-key.json.
- Install and run MongoDB locally, or use a cloud provider (e.g., MongoDB Atlas).
- Update
.envwith your MongoDB connection details.
- Install and run Redis locally, or use a managed Redis service.
- Update
.envwith your Redis connection details.
- Use a real SMTP provider (Gmail, SendGrid, Mailgun, etc.).
- Update
.envwith your SMTP credentials.
yarn dev
# or
npm run devyarn build
yarn start
# or
npm run build
npm startbackend/
├── src/
│ ├── config/ # Configuration (db, logger, email, etc.)
│ ├── middleware/ # Express middlewares
│ ├── module/ # Feature modules (auth, user, otp, media, etc.)
│ ├── templates/ # Email templates
│ ├── types/ # TypeScript type definitions
│ ├── route.ts # Main route registry
│ └── server.ts # Express app/server setup
├── logs/ # Log files (gitignored)
├── .env.example # Example environment variables
├── google-cloud-key.json # Google Cloud credentials (not committed)
├── package.json
├── tsconfig.json
└── README.md
yarn dev/npm run dev- Start development server with hot reloadyarn build/npm run build- Compile TypeScript todist/yarn start/npm start- Run compiled server
- Do not commit sensitive files:
.env,google-cloud-key.json, andlogs/are gitignored. - Email templates: Located in
src/templates/email/. Use{{variable}}syntax for dynamic values. - Adding modules: Use
module-create.shto scaffold new modules. - Logging: All requests and errors are logged to
logs/and rotated automatically. - API base path: All routes are prefixed with
/api/v1.
- MongoDB/Redis connection errors: Check your
.envvalues and ensure services are running. - Google Cloud errors: Ensure
google-cloud-key.jsonis present and valid, and bucket exists. - SMTP errors: Verify SMTP credentials and network access.
- CORS issues: Update allowed origins in
src/server.tsand.envas needed.
MIT