A RESTful API for managing contacts, built with Node.js, Express, and SQLite. Project 4 in a sequential backend engineering learning journey — the first project in the series with real persistent storage instead of an in-memory array.
- Full CRUD for contacts (Create, Read, Update, Delete)
- Persistent storage via SQLite (data survives server restarts)
- Async/await throughout, with try/catch + centralized error handling
- Parameterized SQL queries (SQL-injection safe)
- Email format validation
- Clean MVC-style structure (config / routes / controllers / models)
- Node.js
- Express
- SQLite (via
sqlite3+sqlite)
npm install
npm run devServer runs on http://localhost:3003. A data.db SQLite file is created
automatically on first run.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/contacts | Get all contacts |
| GET | /api/contacts/:id | Get a single contact |
| POST | /api/contacts | Create a new contact |
| PUT | /api/contacts/:id | Update a contact |
| DELETE | /api/contacts/:id | Delete a contact |
{
"name": "Jane Doe",
"email": "jane@example.com",
"phone": "555-1234"
}src/ ├── config/ - Database connection setup ├── models/ - SQL queries (async) ├── controllers/ - Request handling, validation, error routing ├── routes/ - URL-to-controller mapping └── middleware/ - Centralized error handling
- A real SQLite database with a persistent
.dbfile - Async/await across the model and controller layers
try/catch+next(err)in every controller function, routing failures to the (unchanged) centralized error handler