A simple Notes API built with Node.js and Express.js.
This project implements basic CRUD operations (Create, Read, Update, Delete) for managing notes stored in memory.
- Create a new note with a title and content.
- Get all notes or a single note by ID.
- Update an existing note.
- Delete a note by ID.
- JSON-based API responses.
- Error handling for invalid requests.
project-root/
│── index.js # Main server file
│── package.json # Dependencies and scripts
└── README.md # Project documentation
git clone <your-repo-url>
cd notes-apinpm installnpm startThe server will start on:
http://localhost:3000
GET /
Response: "Welcome to Notes API 📒"
POST /notes
Request body:
{ "title": "My first note", "content": "This is the content of my note" }Response:
{ "id": 1, "title": "My first note", "content": "This is the content of my note" }GET /notes
Response:
[
{ "id": 1, "title": "My first note", "content": "This is the content of my note" }
]GET /notes/:id
Example:
GET /notes/1Response:
{ "id": 1, "title": "My first note", "content": "This is the content of my note" }PUT /notes/:id
Request body (fields optional):
{ "content": "Updated content" }Response:
{ "id": 1, "title": "My first note", "content": "Updated content" }DELETE /notes/:id
Response:
{ "message": "Note deleted" }- Validation to ensure
titleandcontentare required when creating a note. - Add
createdAttimestamp to each note.