A simple Express.js CRUD API for notes using in-memory storage.
This project is built to understand the core CRUD operations in Express.js.
It covers:
- creating a note
- reading all notes
- reading a single note
- updating a note
- deleting a note
- separating code into routes and controllers
- using JSON request bodies
- testing APIs with a REST client
- Node.js
- Express.js
- Nodemon
- GET all notes
- GET single note by id
- POST create note
- PUT update note
- DELETE note
- in-memory data storage using a local array
- modular folder structure with routes and controllers
express-project-07-simple-crud-api
│
├── src
│ ├── controllers
│ │ └── notes.controller.js
│ └── routes
│ └── notes.route.js
│
├── api-test.rest
├── index.js
├── package.json
├── package-lock.json
└── .gitignoreClone the repository:
git clone https://github.com/a2rp/express-project-07-simple-crud-api.git
cd express-project-07-simple-crud-apiInstall dependencies:
npm installRun in development mode:
npm run devRun normally:
npm startServer runs at:
http://localhost:1198GET /Response:
{
"success": true,
"message": "Simple CRUD API is running"
}GET /notesGET /notes/:idExample:
GET /notes/1POST /notes
Content-Type: application/jsonRequest body:
{
"title": "New Note",
"content": "This is a new note"
}PUT /notes/:id
Content-Type: application/jsonExample body:
{
"title": "Updated Note Title",
"content": "Updated note content"
}DELETE /notes/:idYou can test the API using:
- VS Code REST Client extension with
api-test.rest - Postman
- Thunder Client
- browser for GET routes
This project uses in-memory storage.
That means:
- notes are stored in a JavaScript array
- data is not saved in a real database
- restarting the server resets the data
This is useful for learning CRUD logic before moving to MongoDB or another database.
By building this project, you learn how to:
- build a CRUD API in Express.js
- organize backend code using routes and controllers
- work with request params and request body
- send proper JSON responses
- handle simple validation
- test APIs during development
- connect MongoDB for persistent storage
- add request validation
- use UUID instead of manual id generation
- add timestamps
- add error handling middleware
Ashish Ranjan
Follow me:
- GitHub: https://github.com/a2rp
- Portfolio: https://www.ashishranjan.net
- LinkedIn: https://www.linkedin.com/in/aashishranjan
- Facebook: https://www.facebook.com/theash.ashish/