Skip to content

bahuan-coding/notes-crud-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Notes CRUD API

Node.js Express Jest Coverage License

Professional Node.js REST API for managing notes with comprehensive testing and interview-ready architecture

A production-quality CRUD API built with Express.js, featuring comprehensive input validation, error handling, and a robust test suite. Designed to demonstrate senior-level backend engineering skills.

✨ Features

  • Complete CRUD Operations - Create, read, update, and delete notes
  • Professional Architecture - Clean separation of concerns with layered design
  • Comprehensive Validation - Input sanitization and detailed error messages
  • Robust Error Handling - Proper HTTP status codes and structured responses
  • High Test Coverage - 95%+ coverage with 46 comprehensive test cases
  • Code Quality - ESLint integration with consistent coding standards
  • In-Memory Storage - No external dependencies, perfect for demos
  • CORS Support - Ready for frontend integration
  • Health Monitoring - Built-in health check endpoint

πŸš€ Quick Start

Prerequisites

  • Node.js β‰₯18.0.0
  • npm β‰₯8.0.0

Installation

# Clone the repository
git clone <repository-url>
cd notes-crud-api

# Install dependencies
npm install

# Start the server
npm start

The API will be available at http://localhost:3000

Development Mode

# Start with auto-reload
npm run dev

πŸ“‹ Available Scripts

Command Description
npm start Start the production server
npm run dev Start development server with auto-reload
npm test Run the complete test suite
npm run test:watch Run tests in watch mode
npm run test:coverage Run tests with coverage report
npm run lint Check code quality with ESLint
npm run lint:fix Fix ESLint issues automatically

πŸ”— API Endpoints

Base URL

http://localhost:3000
Method Endpoint Description Status Codes
POST /notes Create a new note 201, 400
GET /notes Retrieve all notes 200
GET /notes/:id Retrieve a specific note 200, 404
PUT /notes/:id Update a note 200, 400, 404
DELETE /notes/:id Delete a note 200, 404
GET /health Health check 200

Request/Response Examples

Create a Note

curl -X POST http://localhost:3000/notes \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Meeting Notes",
    "content": "Discuss project timeline and deliverables"
  }'

Response (201 Created):

{
  "success": true,
  "data": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "title": "Meeting Notes",
    "content": "Discuss project timeline and deliverables",
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:30:00.000Z"
  },
  "message": "Note created successfully"
}

Get All Notes

curl http://localhost:3000/notes

Response (200 OK):

{
  "success": true,
  "data": [
    {
      "id": "123e4567-e89b-12d3-a456-426614174000",
      "title": "Meeting Notes",
      "content": "Discuss project timeline and deliverables",
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    }
  ],
  "count": 1,
  "message": "Notes retrieved successfully"
}

Get Specific Note

curl http://localhost:3000/notes/123e4567-e89b-12d3-a456-426614174000

Update a Note

curl -X PUT http://localhost:3000/notes/123e4567-e89b-12d3-a456-426614174000 \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Meeting Notes",
    "content": "Discuss project timeline, deliverables, and budget"
  }'

Delete a Note

curl -X DELETE http://localhost:3000/notes/123e4567-e89b-12d3-a456-426614174000

Error Responses

Validation Error (400)

{
  "success": false,
  "error": "Validation Error",
  "message": "Title is required and must be a non-empty string"
}

Not Found (404)

{
  "success": false,
  "error": "Not Found",
  "message": "Note not found"
}

πŸ§ͺ Testing & Quality

Test Coverage

The project maintains 95%+ code coverage with comprehensive test scenarios:

  • 46 test cases covering all CRUD operations
  • Validation testing for all input scenarios
  • Error handling for edge cases and failures
  • Integration testing for middleware and server functionality
  • Boundary testing for limits and constraints
# Run all tests
npm test

# Run with coverage report
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Code Quality

# Check code quality
npm run lint

# Auto-fix issues
npm run lint:fix

See TESTING.md for detailed testing documentation and philosophy.

🎬 Demo Script

A complete demo script is provided to showcase all API functionality:

# Make the script executable
chmod +x demo.sh

# Run the complete demo (requires server to be running)
./demo.sh

The demo script demonstrates:

  1. Health check
  2. Creating multiple notes
  3. Retrieving all notes
  4. Getting a specific note
  5. Updating a note
  6. Deleting a note
  7. Error handling scenarios

πŸ—οΈ Architecture

Project Structure

notes-crud-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js              # Express application setup
β”‚   β”œβ”€β”€ server.js           # Server startup and configuration
β”‚   β”œβ”€β”€ middleware/         # Custom middleware
β”‚   β”‚   β”œβ”€β”€ errorHandler.js # Global error handling
β”‚   β”‚   └── validateNote.js # Input validation
β”‚   β”œβ”€β”€ models/             # Data models
β”‚   β”‚   └── Note.js         # Note entity
β”‚   β”œβ”€β”€ routes/             # API route definitions
β”‚   β”‚   └── notes.js        # Notes CRUD endpoints
β”‚   └── services/           # Business logic
β”‚       └── notesService.js # Notes service layer
β”œβ”€β”€ tests/                  # Test suites
β”‚   β”œβ”€β”€ notes.test.js       # API endpoint tests
β”‚   β”œβ”€β”€ server.test.js      # Server integration tests
β”‚   └── setup.js            # Test configuration
β”œβ”€β”€ demo.sh                 # Complete API demo script
β”œβ”€β”€ TESTING.md              # Testing documentation
└── README.md               # This file

Design Principles

  • Layered Architecture - Clear separation between routes, services, and models
  • Error-First Design - Comprehensive error handling at every layer
  • Validation-First - Input validation before processing
  • Test-Driven Quality - High test coverage with meaningful assertions
  • Professional Standards - ESLint, consistent naming, proper HTTP codes

🎯 Interview-Ready Highlights

This project demonstrates:

Technical Excellence

  • βœ… RESTful API design with proper HTTP methods and status codes
  • βœ… Comprehensive input validation and error handling
  • βœ… Professional project structure and code organization
  • βœ… High test coverage (95%+) with meaningful test cases
  • βœ… Code quality enforcement with ESLint
  • βœ… Modern Node.js and Express.js best practices

Senior-Level Patterns

  • βœ… Layered architecture with separation of concerns
  • βœ… Middleware pattern for cross-cutting concerns
  • βœ… Service layer abstraction for business logic
  • βœ… Comprehensive error handling strategy
  • βœ… Professional testing methodology
  • βœ… Clean, maintainable, and scalable code

Production Readiness

  • βœ… Environment-based configuration
  • βœ… Proper logging and monitoring (health check)
  • βœ… CORS support for frontend integration
  • βœ… Input sanitization and validation
  • βœ… Graceful error responses
  • βœ… Documentation and demo scripts

πŸ› οΈ Technology Stack

  • Runtime: Node.js 18+
  • Framework: Express.js 4.18+
  • Testing: Jest 29+ with Supertest
  • Code Quality: ESLint 8+
  • UUID Generation: uuid 9+
  • CORS: cors 2.8+

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

This is a portfolio/interview demonstration project. For suggestions or improvements, please open an issue or submit a pull request.


Built with ❀️ for demonstrating senior backend engineering skills

About

REST API for managing notes with comprehensive testing and interview-ready architecture

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published