This project is a backend server implementation that provides a RESTful API for managing places and users. It is built using Node.js and Express.js, with MongoDB as the database for storing and retrieving data. The server allows users to create, read, update, and delete places, as well as register and authenticate users.
The main features of this project include:
- CRUD operations for managing places, including creating new places, retrieving places by ID or associated user ID, updating place details, and deleting places.
- User registration and login functionality, with secure password hashing and authentication using JSON Web Tokens (JWT).
- Integration with MongoDB for persistent data storage and retrieval.
- Error handling and appropriate HTTP status codes for API responses.
- Input validation and data sanitization using Express.js middleware.
This project serves as a foundation for building applications that require backend functionality for managing places and user authentication. The provided code consists of the server setup, routing, controllers for handling API requests, and the necessary models for working with the data.
Feel free to explore the code and customize it according to your specific requirements and project needs.
- Node.js
- Express.js
- MongoDB
- Mongoose
To run this project locally, follow these steps:
- Clone the repository:
git clone <repository-url>
- Navigate to the project directory:
cd <project-folder>
- Install the dependencies:
npm install
To start the server, use the following command:
npm start
Make sure you have a running MongoDB server and update the connection string in app.js
to match your MongoDB configuration.
The project has the following dependencies:
- express: Fast, unopinionated, minimalist web framework for Node.js.
- body-parser: Node.js body parsing middleware.
- mongoose: MongoDB object modeling tool designed to work in an asynchronous environment.
- express-validator: A set of express.js middlewares that wraps validator.js validator and sanitizer functions.
- uuid: Generate RFC-compliant UUIDs.
The server exposes the following API endpoints:
GET /api/places/:pid
: Retrieves a specific place by ID.GET /api/places/user/:uid
: Retrieves all places associated with a specific user.POST /api/places
: Creates a new place.PATCH /api/places/:pid
: Updates a specific place by ID.DELETE /api/places/:pid
: Deletes a specific place by ID.GET /api/users
: Retrieves all users.POST /api/users/signup
: Registers a new user.POST /api/users/login
: Logs in an existing user.
For detailed information on request and response formats, please refer to the corresponding route files in the routes
directory.
Contributions to this project are welcome. To contribute, follow these steps:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Commit your changes and push them to your forked repository.
- Create a pull request detailing your changes.
Ali OZZAIM