This project is a Node.js API that provides authentication and note management functionalities. It includes routes for user registration, login, password management, and note operations.
-
Authentication
- Register new users
- User login
- Forgot password functionality
-
User Management
- Retrieve current user details
- Update user information
- Change user password
- Retrieve user's notes
-
Note Management
- Create, update, and delete notes
- Retrieve individual notes
-
POST
/auth/login
- Body:
email
,password
- Logs in a user and returns a token.
- Body:
-
POST
/auth/register
- Body:
full_name
,email
,password
- Registers a new user.
- Body:
-
POST
/auth/forgot-password
- Body:
email
- Headers:
Authorization: Bearer <token>
- Initiates a password reset process.
- Body:
-
GET
/users/me
- Headers:
Authorization: Bearer <token>
- Retrieves the current user's information.
- Headers:
-
GET
/users/me/notes
- Headers:
Authorization: Bearer <token>
- Params:
page
(optional, integer) - Retrieves the current user's notes.
- Headers:
-
PUT
/users/me
- Body:
full_name
,email
- Headers:
Authorization: Bearer <token>
- Updates the current user's information.
- Body:
-
PUT
/users/me/password
- Body:
password
,new_password
,new_password_confirmation
- Headers:
Authorization: Bearer <token>
- Updates the current user's password.
- Body:
-
POST
/notes
- Body:
title
,note
- Headers:
Authorization: Bearer <token>
- Creates a new note.
- Body:
-
DELETE
/notes/:noteId
- Headers:
Authorization: Bearer <token>
- Deletes a note by its ID.
- Headers:
-
PUT
/notes/:noteId
- Body:
title
,note
- Headers:
Authorization: Bearer <token>
- Updates a note by its ID.
- Body:
-
GET
/notes/:noteId
- Headers:
Authorization: Bearer <token>
- Retrieves a note by its ID.
- Headers:
project-root/
│
├── Config/
│
├── Controllers/
│ ├── Note/
│ │ ├── CreateNote.js
│ │ ├── DeleteNote.js
│ │ ├── GetNote.js
│ │ └── UpdateNote.js
│ └── User/
│ ├── GetMe.js
│ ├── GetMyNotes.js
│ ├── UpdateMyPassword.js
│ ├── UserUpdateMe.js
│ └── Auth.js
│
├── Middleware/
│ └── Auth.js
│
├── Models/
│ ├── Note/
│ │ └── CreateNote.js
│ └── Auth.js
│
├── Routes/
│ ├── Note/
│ │ ├── CreateNote.js
│ │ ├── DeleteNote.js
│ │ ├── GetNote.js
│ │ └── UpdateNote.js
│ └── User/
│ ├── GetMe.js
│ ├── GetMyNotes.js
│ ├── UpdateMyPassword.js
│ ├── UserUpdateMe.js
│ └── Auth.js
│
├── .env
├── .gitignore
├── index.js
├── package-lock.json
└── package.json
-
Clone the repository:
git clone https://github.com/Veliashvilii/Basic-Note-App-API-NodeJS.git cd basic-note-app-api-nodejs
-
Install dependencies:
npm install
-
Create a
.env
file and configure your environment variables:PORT: The port number on which the server will run. MONGO_URI: The connection string for your MongoDB database. SECRET_TOKEN: A secret key used for signing tokens (e.g., JWT).
-
Start the server:
npm start
-
Testing with Postman
You can use Postman to test the API endpoints. Here's how to set up and send requests:
-
Download and Install Postman:
- Visit the Postman website to download and install the Postman app on your computer.
-
Import API Endpoints:
- You can manually create requests for each endpoint or import a Postman collection if available.
-
Configure Environment Variables:
- Set up environment variables in Postman for easy management of values like
token
,baseURL
, and other dynamic parts of your requests.
- Set up environment variables in Postman for easy management of values like
-
Send Requests:
-
Open Postman and create a new request for the desired endpoint.
-
Example: To test the login endpoint, create a new
POST
request tohttp://localhost:PORT/auth/login
and add a JSON body:{ "email": "[email protected]", "password": "your_password" }
-
Add
Authorization
headers where needed for authenticated routes, using the formatBearer <token>
.
-
-
View Responses:
-
Send the request and check the response for data or error messages. You should see a response similar to:
{ "message": "User logged in successfully", "token": "your_jwt_token_here", "user": { "id": "user_id_here", "full_name": "Your Name", "email": "[email protected]" } }
-
-
Additional Testing:
- Continue to test other endpoints like creating notes, updating user details, etc., by following the same procedure: set the correct method, URL, headers, and body for each request.
-
- Express
- CORS
- Mongoose
- Bcryptjs
- JSONWebToken
- Dotenv
This project is licensed under the ISC License. See the ISC License for more details.
The ISC License is a permissive open-source license that is functionally similar to the MIT License. It allows for software to be freely used, modified, and distributed, provided that the license and copyright notice are included in all copies or substantial portions of the software.
- Permissions: Allows for copying, modifying, merging, publishing, distributing, sublicensing, and selling the software.
- Conditions: Must include the original copyright notice and license text in all copies or substantial portions of the software.
- Limitation: The software is provided "as is," without warranty of any kind.