|
| 1 | +# Notes API |
| 2 | + |
| 3 | +A RESTful API for managing personal notes with user authentication. Built with Node.js, Express, and MongoDB. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- User registration and authentication |
| 8 | +- Create, read, update, and delete notes |
| 9 | +- Search notes by title |
| 10 | +- Filter notes by tags |
| 11 | +- Pagination for note listings |
| 12 | +- Archive and pin notes |
| 13 | +- Secure routes with authentication middleware |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +1. Clone the repository: |
| 18 | + ``` |
| 19 | + git clone <repository-url> |
| 20 | + cd notes-api |
| 21 | + ``` |
| 22 | + |
| 23 | +2. Install dependencies: |
| 24 | + ``` |
| 25 | + npm install |
| 26 | + ``` |
| 27 | + |
| 28 | +3. Set up environment variables: |
| 29 | + Create a `.env` file in the root directory with the following: |
| 30 | + ``` |
| 31 | + SECRET=your-secret-key |
| 32 | + PORT=3000 |
| 33 | + ``` |
| 34 | + |
| 35 | +4. Start MongoDB locally or update the connection string in `index.js` if using a remote database. |
| 36 | + |
| 37 | +5. Run the application: |
| 38 | + ``` |
| 39 | + node index.js |
| 40 | + ``` |
| 41 | + |
| 42 | +The server will start on port 3000 (or the port specified in `.env`). |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +The API provides endpoints for user authentication and note management. All note-related endpoints require authentication except registration and login. |
| 47 | + |
| 48 | +### Authentication |
| 49 | + |
| 50 | +- Register a new user with POST `/register` |
| 51 | +- Login with POST `/login` |
| 52 | +- Logout with POST `/logout` |
| 53 | +- Get user profile with GET `/profile` |
| 54 | + |
| 55 | +### Notes |
| 56 | + |
| 57 | +- Create a note: POST `/notes` |
| 58 | +- Get all notes: GET `/notes` (supports query parameters for search, tag, page, limit) |
| 59 | +- Get a specific note: GET `/notes/:id` |
| 60 | +- Update a note: PUT `/notes/:id` |
| 61 | +- Delete a note: DELETE `/notes/:id` |
| 62 | + |
| 63 | +## API Endpoints |
| 64 | + |
| 65 | +### Authentication Routes |
| 66 | + |
| 67 | +| Method | Endpoint | Description | Auth Required | |
| 68 | +|--------|--------------|--------------------------|---------------| |
| 69 | +| POST | /register | Register a new user | No | |
| 70 | +| POST | /login | Login user | No | |
| 71 | +| POST | /logout | Logout user | Yes | |
| 72 | +| GET | /profile | Get user profile | Yes | |
| 73 | + |
| 74 | +### Notes Routes |
| 75 | + |
| 76 | +| Method | Endpoint | Description | Auth Required | |
| 77 | +|--------|--------------|--------------------------|---------------| |
| 78 | +| POST | /notes | Create a new note | Yes | |
| 79 | +| GET | /notes | Get all user notes | Yes | |
| 80 | +| GET | /notes/:id | Get a specific note | Yes | |
| 81 | +| PUT | /notes/:id | Update a note | Yes | |
| 82 | +| DELETE | /notes/:id | Delete a note | Yes | |
| 83 | + |
| 84 | +Query parameters for GET /notes: |
| 85 | +- `q`: Search term for title (case-insensitive) |
| 86 | +- `tag`: Filter by tag |
| 87 | +- `page`: Page number for pagination (default 1) |
| 88 | +- `limit`: Number of notes per page (default 10) |
| 89 | + |
| 90 | +## Models |
| 91 | + |
| 92 | +### User |
| 93 | +- `email`: String (required, unique) |
| 94 | +- `username`: String (handled by passport-local-mongoose) |
| 95 | +- `password`: String (hashed by passport-local-mongoose) |
| 96 | + |
| 97 | +### Note |
| 98 | +- `title`: String (required, max 50 characters) |
| 99 | +- `content`: String (required, min 3 characters) |
| 100 | +- `tags`: Array of Strings (required) |
| 101 | +- `user`: ObjectId (reference to User) |
| 102 | +- `isArchived`: Boolean (default false) |
| 103 | +- `isPinned`: Boolean (default false) |
| 104 | +- `createdAt`: Date |
| 105 | +- `updatedAt`: Date |
| 106 | + |
| 107 | +## Technologies Used |
| 108 | + |
| 109 | +- Node.js |
| 110 | +- Express.js |
| 111 | +- MongoDB |
| 112 | +- Mongoose |
| 113 | +- Passport.js (with Local Strategy) |
| 114 | +- Express Session |
| 115 | + |
| 116 | +## Contributing |
| 117 | + |
| 118 | +1. Fork the repository |
| 119 | +2. Create a feature branch |
| 120 | +3. Make your changes |
| 121 | +4. Submit a pull request |
| 122 | + |
| 123 | +## License |
| 124 | + |
| 125 | +This project is licensed under the ISC License. |
0 commit comments