This repository contains the backend services for managing database operations and server-side logic for both web and mobile applications. It is built using Node.js, Express, and TypeScript, with MongoDB as the database.
-
Authentication and Authorization:
- User login and registration.
- Role-based access control (RBAC) for different user types.
- JWT-based authentication.
-
File Upload:
- Integration with AWS S3 for file storage using
multer
andmulter-s3
.
- Integration with AWS S3 for file storage using
-
Database Management:
- MongoDB models for users, locations, contacts, and path logs.
- Middleware to ensure database connectivity.
-
Email Notifications:
- Integration with Brevo (Sendinblue) for sending transactional emails.
-
API Documentation:
- Swagger integration for API documentation.
-
Utilities:
- Validation utilities for email, password, and username.
- Helper functions for generating presigned URLs for S3.
src/
├── config/ # Configuration files (e.g., multer for file uploads)
├── controllers/ # Controllers for handling API logic
├── middlewares/ # Middleware for authentication, authorization, and database connection
├── models/ # Mongoose models for MongoDB collections
├── routes/ # API route definitions
├── types/ # TypeScript type definitions
├── utils/ # Utility functions and helpers
├── index.ts # Entry point of the application
- Node.js (v18 or higher)
- MongoDB (local or cloud instance)
- AWS S3 (for file storage)
- Brevo (Sendinblue) API key (for email notifications)
-
Clone the repository:
git clone https://github.com/Computer-Aided-Navigation-Equipment/backend.git cd backend
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory and add the following environment variables:PORT=6001 DBURI=<your-mongodb-uri> JWT_SECRET=<your-jwt-secret> BREVO_API_KEY=<your brevo-api-key> FRONTEND_URL=<your frontend-url> AWS_ACCESS_KEY_ID=<your-aws-access-key-id> AWS_SECRET_ACCESS_KEY=<your-aws-secret-access-key> AWS_REGION=<your-aws-region> S3_BUCKET_NAME=<your-s3-bucket-name>
-
Build the project:
npm run build
-
Start the server:
npm run dev
POST /api/user/register
- Register a new user.POST /api/user/login
- Login a user.POST /api/user/change-password
- Change user password.GET /api/user/profile
- Get user profile.
POST /api/location/create
- Create a new location.GET /api/location/get-user
- Get all locations for a user.POST /api/location/delete/:locationId
- Delete a location.
POST /api/contact/create
- Create a new contact.GET /api/contact/get-user
- Get all contacts for a user.POST /api/contact/delete/:contactId
- Delete a contact.
POST /api/pathlog/create
- Create a new path log.
Access the API documentation at http://localhost:6001/api-docs
.
npm run build
- Compile TypeScript to JavaScript.npm run start
- Start the production server.npm run dev
- Start the development server with hot-reloading.npm run test
- Run tests using Jest.