This project is a backend API for managing car owners and their vehicles. It is built using Node.js, Express, and MongoDB and follows a RESTful API design pattern. The API supports essential CRUD operations for owners and cars, along with secure authentication using JWT.
Owner Management: Create, update, view, and delete owner records.
Car Management: Add new cars, view car details, update car information, and remove cars.
Authentication: Login functionality using JWT for secure access.
Error Handling: Handles errors gracefully with custom error messages.
RESTful API: Clean and structured endpoint design.
Node.js: Backend runtime environment.
Express: Web framework for building API endpoints.
MongoDB: NoSQL database for persisting owner and car data.
JWT (jsonwebtoken): Authentication and secure access.
Mongoose: MongoDB object modeling for Node.js.
Bcrypt: For securely hashing passwords.
Owner Endpoints
POST /owners - Create a new owner.
POST /owners/login - Login an owner and generate a JWT token.
GET /owners - Retrieve all owners.
GET /owners/detail - Retrieve detailed information about a specific owner.
PUT /owners/{ownerId} - Fully update an owner's details.
PATCH /owners/{ownerId} - Partially update an owner's details.
DELETE /owners/{ownerId} - Delete an owner.
Car Endpoints
POST /cars - Create a new car.
GET /cars - Retrieve all cars.
GET /cars/{carId} - Retrieve a specific car's details.
PUT /cars/{carId} - Update car information.
DELETE /cars/{carId} - Delete a car.
Clone the repository:
bash or terminal
Copy code
git clone https://github.com/yourusername/yourprojectname.git
Install dependencies:
bash or terminal
Copy code;
npm install
Create a .env file in the root directory and configure the following environment variables:
Add the variables below to .env file;
DB_URI=mongodb://localhost:27017/techyjauntcars
PORT=4500
JWT_SECRET=your_jwt_secret_here
bash or teminal
Copy code
npm start
The API will now be available at http://localhost:4500.
express: Web framework for Node.js.
jsonwebtoken: For generating and verifying JWTs.
mongoose: MongoDB object modeling.
bcrypt: For password hashing and salting.
dotenv: Loads environment variables from a .env file.
body-parser: Middleware for parsing request bodies.
express-async-handler: Simplifies error handling for async functions.
To test the API, you can import the provided Insomnia workspace and test the endpoints directly.
Download the insomnia/api-requests.json file from this repository.
Open Insomnia and go to Application Menu > Import/Export > Import Data.
Select the downloaded api-requests.json file to load the API requests for this project.
This project is licensed under the MIT License.