Welcome to the Travel project! This is a learning project for building a Node.js backend with MongoDB for managing travel-related data. The project structure is designed to help you get started with creating APIs, handling database operations, and more.
- Project Structure
- Environment Variables
- Database Connection
- Creating Routes and Controllers
- Setting Up Express App
- API Documentation with Swagger
- Running the Project
The project follows a structured directory layout:
Travel/
├── src/
│ ├── controller/
│ ├── db/
│ ├── middleware/
│ ├── model/
│ ├── routes/
│ ├── utils/
│ └── index.ts
├── .env
├── .gitignore
├── package.json
├── tsconfig.json
└── README.md
src/
: Contains different components of the application..env
: Environment variable configuration..gitignore
: Specifies files and directories to be ignored by version control.package.json
: Lists dependencies and project details.tsconfig.json
: TypeScript compiler configuration.
Create a .env
file in the project root and add your environment variables:
mongoDB=mongodb+srv://your-mongodb-uri
mySecret=your-secret-key
API=http://localhost:4001
Env=local
The database connection is established in db/Dbconnect.ts
. The connectDb
function uses mongoose to connect to MongoDB.
Define your application's routes and controllers. For example, routes/hotelRoutes.ts
and controller/Hotel.ts
handle hotel-related functionality.
In src/index.ts
, the Express app is configured. The server listens on the specified port, and middleware for handling requests and responses is set up.
API documentation is generated using Swagger. The swagger.json
file defines API paths and definitions. Access the documentation at http://localhost:4001/api-docs
.
-
Install project dependencies:
yarn
-
Run the project
yarn run dev
This starts the server with nodemon, providing live-reloading during development.
Feel free to expand upon this foundation by adding more routes, controllers, models, and other functionalities to create a fully featured travel application. Happy coding!
** Author:**
** Other Team Member **
** Recourse **