This is the backend application for the Tourist Guide project. It is built with Node.js, Express.js, TypeScript, and MongoDB. The backend handles tours, bookings, users, payments, and reviews.
Live Demo: https://tourist-guide-backend.vercel.app
- REST API for tours, bookings, and users
- Payment processing via Stripe
- User authentication and authorization (JWT)
- Review system for tours and guides
- MongoDB database integration
- Error handling and validation
Make sure you have the following installed:
- Clone the repository
git clone https://github.com/your-username/tourist-guide-backend.git
cd tourist-guide-backend- Install dependencies
npm install
# or
yarn install- Create environment variables
Create a .env file in the root:
PORT=5000
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/tourist-guide
JWT_SECRET=your_jwt_secret_key
STRIPE_SECRET_KEY=sk_test_yourkey
FRONTEND_URL=http://localhost:3000Replace with your actual MongoDB URI, Stripe secret key, and JWT secret.
- Run the development server
npm run dev
# or
yarn dev- Server runs on http://localhost:5000
- Build the project
npm run build
# or
yarn build- Start the production server
npm start
# or
yarn start- Make sure MongoDB Atlas or production database is accessible.
- Ensure
FRONTEND_URLis set correctly for CORS.
backend/
│
├─ src/
│ ├─ controllers/ # API route controllers
│ ├─ models/ # Mongoose models
│ ├─ routes/ # Express routes
│ ├─ middleware/ # Auth, error handling, etc.
│ ├─ services/ # Stripe and other service logic
│ └─ utils/ # Helper functions
├─ .env # Environment variables
├─ package.json # Dependencies and scripts
├─ tsconfig.json # TypeScript configuration
└─ README.md # Project documentation
| Command | Description |
|---|---|
npm run dev |
Run server in development mode with nodemon |
npm run build |
Compile TypeScript for production |
npm start |
Start production server |
npm run lint |
Lint code |
npm run format |
Format code with Prettier |
-
MongoDB connection errors
- Ensure
MONGO_URIis correct and your IP is whitelisted in MongoDB Atlas
- Ensure
-
Stripe payment errors
- Ensure
STRIPE_SECRET_KEYis valid - Check your frontend is sending the correct request
- Ensure
-
JWT authentication errors
- Make sure
JWT_SECRETis consistent between backend and frontend
- Make sure
-
CORS issues
- Ensure
FRONTEND_URLis added to CORS whitelist in your Express app
- Ensure