Skip to content

a2rp/express-project-07-simple-crud-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-project-07-simple-crud-api

A simple Express.js CRUD API for notes using in-memory storage.

Project Goal

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

Tech Stack

  • Node.js
  • Express.js
  • Nodemon

Features

  • 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

Project Structure

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
└── .gitignore

Installation

Clone the repository:

git clone https://github.com/a2rp/express-project-07-simple-crud-api.git
cd express-project-07-simple-crud-api

Install dependencies:

npm install

Run the Project

Run in development mode:

npm run dev

Run normally:

npm start

Server runs at:

http://localhost:1198

API Endpoints

Root Route

GET /

Response:

{
    "success": true,
    "message": "Simple CRUD API is running"
}

Get All Notes

GET /notes

Get Single Note

GET /notes/:id

Example:

GET /notes/1

Create Note

POST /notes
Content-Type: application/json

Request body:

{
    "title": "New Note",
    "content": "This is a new note"
}

Update Note

PUT /notes/:id
Content-Type: application/json

Example body:

{
    "title": "Updated Note Title",
    "content": "Updated note content"
}

Delete Note

DELETE /notes/:id

Testing APIs

You can test the API using:

  • VS Code REST Client extension with api-test.rest
  • Postman
  • Thunder Client
  • browser for GET routes

Important Note

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.

Learning Outcome

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

Future Improvements

  • connect MongoDB for persistent storage
  • add request validation
  • use UUID instead of manual id generation
  • add timestamps
  • add error handling middleware

Author

Ashish Ranjan

Follow me:

About

Simple Express.js CRUD API for notes using in-memory storage.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors