This project showcases a Node.js backend architecture using TypeScript with MongoDB hosted on Azure Cosmos. It includes basic CRUD operations.
- Node.js
- Express.js
- TypeScript
- MongoDB (Mongoose)
- Azure Cosmos (MongoDB API)
The project follows a Model-View-Controller (MVC) architecture:
- Models: Defined using Mongoose schemas (
userModel.ts). - Controllers: Handle request/response logic (
userController.ts). - Routes: Define application routes (
userRoutes.ts). - Middleware: Includes validation middleware using
express-validator.
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.envfile in the root directory and add the following:DB_URI=mongodb+srv://<username>:<password>@<your-cosmosdb-account>.mongo.cosmos.azure.com/<database-name>?ssl=true&replicaSet=globaldb PORT=8080Replace
<username>,<password>,<your-cosmosdb-account>, and<database-name>with your actual MongoDB credentials and database information. -
Run the application:
npm start
This will start the server at
http://localhost:8080.
For development purposes, you can run the TypeScript compiler in watch mode and nodemon to automatically restart the server:
npm run watchFor deployment, ensure you have environment-specific configurations set up and use appropriate deployment tools or services (e.g., Azure App Service, AWS Elastic Beanstalk, Docker).
This project is licensed under the MIT License.