A Node.js backend project built with TypeScript, Express, and MongoDB.
- TypeScript support
- Express.js web framework
- MongoDB with Mongoose ODM
- JWT authentication
- Google OAuth 2.0 integration
- Password hashing with bcrypt
- Testing with Jest and Supertest
- Development with hot reload using nodemon
- Node.js (v16 or higher)
- npm or yarn
- MongoDB (local or cloud instance)
- Clone the repository:
git clone <repository-url>
cd tsbackend- Install dependencies:
npm install- Set up environment variables:
Edit the
.envfile with your configuration values.
Start the development server with hot reload:
npm run devBuild the project for production:
npm run buildStart the production server:
npm startRun tests:
npm testRun tests in watch mode:
npm run test:watchRun tests with coverage:
npm run test:coveragesrc/
├── controllers/ # Route controllers
├── models/ # Mongoose models
├── routes/ # Express routes
├── middleware/ # Custom middleware
├── config/ # Configuration files
├── utils/ # Utility functions
└── index.ts # Application entry point
npm run dev- Start development server with hot reloadnpm run build- Build the project for productionnpm start- Start the production servernpm test- Run testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report
Configure the following variables in your .env file:
-
PORT- Server port (default: 3000) -
MONGODB_URI- MongoDB connection string -
JWT_SECRET- Secret key for JWT tokens -
JWT_EXPIRES_IN- JWT token expiration time -
GOOGLE_CLIENT_ID- Google OAuth client ID -
GOOGLE_CLIENT_SECRET- Google OAuth client secret -
GOOGLE_CALLBACK_URL- Google OAuth callback URL -
SESSION_SECRET- Session secret key
ISC
The repository includes a deployment workflow at .github/workflows/deploy.yml with:
- CI (lint, test, build)
- Docker image publish to GHCR
- Deployment jobs currently disabled until hosting platform is selected (AWS/GCP/Railway)
On each target server (staging and production), keep this project checked out at your app directory with:
docker-compose.ymldocker-compose.prod.yml.env
The deploy job runs:
IMAGE_TAG=<tag> docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --pull always apiCreate environments named staging and production in GitHub, then set:
- Shared:
GHCR_USERNAMEGHCR_TOKEN(PAT withread:packages)
- Staging:
STAGING_SSH_HOSTSTAGING_SSH_PORT(optional, defaults to22)STAGING_SSH_USERSTAGING_SSH_KEYSTAGING_APP_DIR(absolute path to repo on server)
- Production:
PROD_SSH_HOSTPROD_SSH_PORT(optional, defaults to22)PROD_SSH_USERPROD_SSH_KEYPROD_APP_DIR(absolute path to repo on server)
- Push to
main: runs CI and publishes Docker image to GHCR - Manual run (
workflow_dispatch): can trigger image build/publish flow - Deployment steps remain commented until platform decision is finalized
ENVIRONMENT.md- environment variable contractRELEASE.md- release and rollback processRUNBOOK.md- incident response and health checksSECURITY.md- secrets and operational security policyHOSTING_DECISION.md- platform selection matrix
- Scheduled synthetic health checks are configured in:
.github/workflows/healthcheck-monitor.yml
- The workflow checks your
HEALTHCHECK_URLevery 15 minutes. - If configured, it sends a webhook alert on failure.
Required repository/environment secrets:
HEALTHCHECK_URL(example:https://your-api-domain/api/v1/health)ALERT_WEBHOOK_URL(optional: Slack/Teams/Discord webhook)