Backend for a note-taking application built with Node.js, Express, and MongoDB. This REST API allows users to create, read, update, and delete notes, with user roles and authentication implemented for secure access.
- User Authentication: Secure signup and login functionality using bcrypt for password encryption.
- Role-Based Access Control: Different user roles ("user", "admin", "moderator") with varying levels of access.
- CRUD Operations for Notes:
- Create: Add new notes with a title and content.
- Read: Retrieve notes.
- Update: Edit existing notes.
- Delete: Remove notes.
- API Documentation: Comprehensive documentation of all API endpoints.
- Environment Configuration: Utilizes environment variables for configuration.
- Backend: Node.js, Express
- Database: MongoDB
- Security: bcrypt
- Deployment: Render
- Version Control: Git, GitHub
MONGO_URI=your_mongodb_connection_string PORT=5000 JWT_SECRET=your_jwt_secret_key 4. Set up environment variables:
- Create a
.envfile in the root directory. - Add the necessary environment variables (e.g.,
MONGO_URI,PORT,JWT_SECRET).
- Start the development server:
bash npm start
- JWT (JSON Web Tokens) is used for authentication.
- Upon successful login, the server returns a JWT that must be included in the
Authorizationheader of subsequent requests. - Example:
Authorization: Bearer <token>
- User: Can create, read, update, and delete their own notes.
- Admin: Has full access, including managing users and notes.
-
Description: Registers a new user.
-
Request Body:
-
Response:
- Success (201 Created):
json
{
"message": "User registered successfully",
"user": {
"id": "user_id",
"name": "string",
"email": "string",
"role": "string"
}
}
json
{
"message": "Login successful",
"token": "jwt_token"
}
> Authentication Required: All notes routes require a valid JWT in the Authorization header.
- Description: Creates a new note.
- Request Body:
json { "message": "Note created successfully", "note": { "id": "note_id", "title": "string", "content": "string", "createdBy": "user_id" } } - Description: Retrieves all notes for the authenticated user.
- Response:
- Success (200 OK):
json { "title": "string", // optional "content": "string" // optional }
- Response:
- Success (200 OK):
json { "message": "You are not authorized to update this note" } - Description: Deletes a note.
-
Request Parameters:
id: The ID of the note to delete.
-
Response:
-
Success (200 OK):
json { "message": "Note not found" }
- The API returns appropriate HTTP status codes for different scenarios:
-
200 OK: Success
-
201 Created: Resource created successfully
-
400 Bad Request: Invalid request data
-
401 Unauthorized: Authentication required
-
403 Forbidden: User does not have permission
-
404 Not Found: Resource not found
-
500 Internal Server Error: Generic server error
-
-
Error responses include a
messagefield with details about the error.
The backend is deployed on Render. Here are the steps for deploying your own instance:
- Create a Render account.
- Connect your GitHub repository to Render.
- Configure the environment variables in Render's dashboard.
- Deploy the application.
Note: Ensure that the
MONGO_URIenvironment variable is correctly configured in Render.
- Deployed Backend URL: https://noteme-gtbw.onrender.com/
- GitHub Project Link: https://github.com/girijakangutkar/NoteAppBackend