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
.env
file with your configuration values.
Start the development server with hot reload:
npm run dev
Build the project for production:
npm run build
Start the production server:
npm start
Run tests:
npm test
Run tests in watch mode:
npm run test:watch
Run tests with coverage:
npm run test:coverage
src/
├── 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