Skip to content

8widerstand/node-sqlite-api

Repository files navigation

node-sqlite-api

🚀 Node.js REST API – Progressive Learning Project

Node.js Version Express.js SQLite License PRs Welcome

📖 Table of Contents


🎯 About The Project

This project documents a complete learning journey from zero to a production-ready REST API. Starting with Node.js native HTTP module, progressing through Express.js, and finally integrating SQLite for persistent data storage, this API serves as both a practical application and a learning portfolio piece.

What is this project?
A RESTful API that manages items (to-do style resources) with full CRUD operations – Create, Read, Update, Delete.

Why build it?
Learning by doing is the most effective way to master backend development. Each step builds on the previous one, with exercises to verify understanding along the way [citation:10].

👥 Who is this for?

  • Beginner developers learning backend development
  • Students wanting to understand REST APIs with a simple database
  • Portfolio builders looking for a clean, well-documented starter project

🗺️ Learning Journey

This project follows a progressive 13-step learning path:

Step Topic What You Learn
1 Project Setup npm init, package.json structure
2 Native HTTP Server http.createServer(), req/res objects
3 Routing (natif) URL parsing, conditional responses
4 Express.js Routes: GET, POST, PUT, DELETE
5 Middlewares Logger, express.json()
6 Route Parameters :id params, query strings
7 SQLite Setup Database creation, tables
8 CRUD with SQLite INSERT, SELECT, UPDATE, DELETE
9 Code Refactor Routes → Controllers → DB separation
10 Error Handling HTTP status codes, try/catch middleware
11 Input Validation Required fields, data types
12 Environment Variables .env files, dotenv
13 Testing curl, Postman, automated tests

Each step includes hands-on exercises and verification methods to ensure you truly understand before moving forward.


💾 Why SQLite?

Unlike MongoDB or PostgreSQL, SQLite requires no separate database server installation – everything lives in a single file. Here's why it's perfect for learning [citation:2][citation:4]:

Criteria SQLite MongoDB
Installation npm install better-sqlite3 Separate server + configuration
Configuration Zero Authentication, file config
Portability Single .db file Multiple folders/files
Learning Curve SQL (universal) MQL (MongoDB-specific)

The SQL you learn transfers directly to PostgreSQL, MySQL, and every other relational database.


✨ Features

Core Functionality

  • Full CRUD Operations – Create, Read, Update, Delete resources via REST endpoints
  • SQLite Database – File-based storage with better-sqlite3
  • Modular Architecture – Routes, controllers, and database layers separated [citation:1]
  • Proper HTTP Status Codes – 200, 201, 400, 404, 500 as appropriate

Middleware & Security

  • Custom request logging middleware
  • JSON body parsing with express.json()
  • Centralized error handling middleware
  • Input validation for required fields

Developer Experience

  • Nodemon for auto-restart during development
  • Environment variables with dotenv
  • Clear project structure following best practices [citation:5]
  • Ready-to-use Postman collection

🧰 Tech Stack

Layer Technology Why
Runtime Node.js (≥18) JavaScript everywhere, massive ecosystem
Framework Express.js 4.x Minimal, flexible, industry standard
Database SQLite + better-sqlite3 Zero configuration, synchronous, perfect for learning
Validation Manual + schema checks Lightweight, no extra dependencies
Testing node:test + curl Built-in, no extra setup

🏗️ Architecture

The application follows an MVC-inspired pattern with clear separation of concerns [citation:1]:

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors