- Node.js installed on your machine.
- A MongoDB Atlas account or a local MongoDB server.
-
Clone the repository or download the code.
-
Install the required dependencies by running the following command:
npm install
-
Open the `app.js` file and replace the `dbURL` variable with your MongoDB connection string. If you're using a local MongoDB server, the URL might look like `mongodb://localhost:27017/mydatabase`.
-
Start the server using the following command:
node app.js
-
The server will start running at `http://localhost:3000\`. You can test it by accessing `http://localhost:3000/\` in your browser, and you should see the message "Hello!".
The API provides the following endpoints for managing cars, users, and brands:
- `GET /api/cars` - Get all cars.
- `GET /api/cars/:id` - Get a car by ID.
- `POST /api/cars` - Create a new car.
- `GET /api/users` - Get all users.
- `GET /api/users/:id` - Get a user by ID.
- `POST /api/users\register` - Create a new user.
- `POST /api/users\login` - login a user.
- `PUT /api/users/:id` - Update a user by ID.
- `DELETE /api/users/:id` - Delete a user by ID.
- `GET /api/brands` - Get all brands.
- `GET /api/brands/:id` - Get a brand by ID.
- `POST /api/brands` - Create a new brand.
- `PUT /api/brands/:id` - Update a brand by ID.
- `DELETE /api/brands/:id` - Delete a brand by ID.
You can use tools like Postman or cURL to send requests to these endpoints and manage the data.
Make sure to handle errors and validations appropriately and provide proper error messages or responses to the API consumers.
That's it! You have successfully set up the Express MongoDB API server. You can now start using the API endpoints to manage cars, users, and brands in your MongoDB database.