This is a RESTful API built using Express.js, MongoDB, and JSON Web Token (JWT) for handling user registration, login, and managing notes. The API supports the following features:
- Endpoint:
POST /create-account
- Description: Registers a new user by accepting
fullName
,email
, andpassword
. If the user already exists, an error message will be returned. - Response: Returns a JSON object with user details and an access token.
- Endpoint:
POST /login
- Description: Authenticates an existing user with
email
andpassword
. Upon successful login, an access token is returned. - Response: Returns a JSON object with a message and the access token.
- Endpoint:
GET /get-user
- Description: Retrieves the logged-in user's information using a valid JWT token. Returns user details like
fullName
,email
, and user_id
. - Response: Returns user details as a JSON object.
- Endpoint:
POST /add-note
- Description: Allows the logged-in user to create a new note. Requires
title
andcontent
fields. Optionally, you can includetags
. - Response: Returns a JSON object with the created note details.
- Endpoint:
PUT /edit-note/:noteId
- Description: Updates an existing note's details (
title
,content
, ortags
). The user must be the owner of the note. - Response: Returns a JSON object with the updated note details.
- Endpoint:
GET /get-all-notes
- Description: Retrieves all notes created by the logged-in user. The notes are sorted by
isPinned
value. - Response: Returns a JSON array of all notes.
- Endpoint:
DELETE /delete-note/:noteId
- Description: Deletes a specific note by
noteId
if the logged-in user is the owner. - Response: Returns a success message upon successful deletion.
- Endpoint:
PUT /update-note-pinned/:noteId
- Description: Updates the
isPinned
status of a note (true or false). - Response: Returns the updated note with a success message.
- Endpoint:
GET /search-notes
- Description: Searches for notes that match a
query
in thetitle
orcontent
of the notes. - Response: Returns a list of notes matching the search query.
This API uses JWT (JSON Web Tokens) for authentication. For most endpoints, a valid JWT token must be passed in the Authorization
header in the format Bearer <token>
.
- Endpoint:
GET /
- Description: Returns the current server status, including the server's uptime and the current server time.
express
: A web framework for Node.js.mongoose
: A MongoDB object modeling tool.jsonwebtoken
: A library to sign and verify JWT tokens.cors
: A package to enable Cross-Origin Resource Sharing.dotenv
: A zero-dependency module that loads environment variables from a.env
file.
ACCESS_TOKEN_SECRET
: Secret key for signing JWT tokens.CONNECTION_STRING
: MongoDB connection string.
Sign Up:
POST /create-account
{
"fullName": "John Doe",
"email": "johndoe@example.com",
"password": "password123"
}
Login:
POST /login
{
"email": "johndoe@example.com",
"password": "password123"
}
Add Note:
POST /add-note
{
"title": "My First Note",
"content": "This is the content of the note.",
"tags": ["important", "personal"]
}