A simple RESTful API built with Node.js, Express, and PostgreSQL for managing student records. This application demonstrates basic CRUD (Create, Read, Update, Delete) operations using a PostgreSQL database.
- Get all students
- Get student by ID
- Add new student with email validation
- Update student information
- Delete student by ID
- Node.js (v20.x or later)
- PostgreSQL (v14.x or later)
- npm (Node Package Manager)
- Create a PostgreSQL database named
students - Create a table with the following structure:
CREATE TABLE students (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255),
age INTEGER,
dob DATE
);- Clone the repository:
git clone https://github.com/zenik-kun/PostgreSQL-CRUD.git- Install dependencies:
npm install- Configure database connection in
db.js:
{
user: "postgres",
host: "localhost",
database: "students",
password: "password",
port: 5432
}Start the server:
node server.jsThe server will start on http://localhost:3000
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/students | Get all students |
| GET | /api/v1/students/:id | Get student by ID |
| POST | /api/v1/students | Add new student |
| PUT | /api/v1/students/:id | Update student name |
| DELETE | /api/v1/students/:id | Delete student |
Add Student (POST):
{
"name": "John Doe",
"email": "john@example.com",
"age": 20,
"dob": "2003-01-01"
}Update Student (PUT):
{
"name": "John Smith"
}- Express.js - Web application framework
- pg - PostgreSQL client for Node.js