https://github.com/mahdibehoftadeh/expressjs-notepad-rest-api
A simple RESTful API for a notepad that uses MongoDB as its database and Express JS as its back-end framework.
https://github.com/mahdibehoftadeh/expressjs-notepad-rest-api
backend expressjs javascript mongodb rest-api
Last synced: 3 months ago
JSON representation
A simple RESTful API for a notepad that uses MongoDB as its database and Express JS as its back-end framework.
- Host: GitHub
- URL: https://github.com/mahdibehoftadeh/expressjs-notepad-rest-api
- Owner: MahdiBehoftadeh
- License: apache-2.0
- Created: 2024-03-23T14:32:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T22:05:23.000Z (almost 2 years ago)
- Last Synced: 2025-01-26T15:31:12.833Z (over 1 year ago)
- Topics: backend, expressjs, javascript, mongodb, rest-api
- Language: JavaScript
- Homepage: https://behoftadeh.ir
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Notes REST API with Express.js and MongoDB - by Mahdi Behoftadeh
This is a REST API for managing notes. It uses Express.js for the server and MongoDB for the database.
## Features
- Create, read, update, and delete notes.
- API routes are under `/api/v1`.
- Data is stored in MongoDB.
## Getting Started
1. **Install dependencies**:
```bash
npm install
```
2. **Set up environment variables**:
Copy `.env.example` file in the root directory and paste it with a new name `.env` and configure its values with yours:
```
API_ROUTE_PREFIX='/api/v1'
DATABASE_CONNECTION_STRING='mongodb://localhost:27017'
```
3. **Start the server**:
```bash
npm start
```
For development with auto-reloading:
```bash
npm run dev
```
The server will run on port 3000 by default.
## API Endpoints
### Notes
- **Get all notes**
- `GET /api/v1/notes`
- Returns a list of all notes.
- **Get a note by ID**
- `GET /api/v1/notes/:id`
- Returns a note by its ID.
- **Create a note**
- `POST /api/v1/notes`
- **Body**:
```json
{
"title": "string",
"text": "string"
}
```
- Creates a new note.
- **Update a note**
- `PATCH /api/v1/notes/:id`
- **Body**:
```json
{
"title": "string",
"text": "string"
}
```
- Updates an existing note by its ID.
- **Delete a note**
- `DELETE /api/v1/notes/:id`
- Deletes a note by its ID.
## Error Handling
- `400 Bad Request`: For invalid data or errors with the request.
- `404 Not Found`: When a note is not found.
- `500 Internal Server Error`: For server or database issues.
## Dependencies
- **Dependencies**:
- `body-parser`: Parses request bodies.
- `express`: Server framework.
- `mongoose`: MongoDB object modeling.
- **DevDependencies**:
- `dotenv`: Loads environment variables.
- `nodemon`: Auto-reloads server during development.
## Links
- **Repository**: [GitHub Repo](https://github.com/MahdiBehoftadeh/expressjs-notepad-rest-api)
- **Issues**: [Issue Tracker](https://github.com/MahdiBehoftadeh/expressjs-notepad-rest-api/issues)
- **Homepage**: [Project Homepage](https://github.com/MahdiBehoftadeh/expressjs-notepad-rest-api#readme)