Skip to content

3mtt Mini Project: Store and Retrieve Data in PostgreSQL

bridgeyuwa/3MTT-ExpressJS-PostgreSQL-CRUD-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Express.js & PostgreSQL CRUD API

Objective

  • Create a simple Express.js API that connects to a PostgreSQL database and performs basic database operations (CRUD - Create, Read, Update, Delete).

Prerequisites

  • Node.js installed
  • PostgreSQL installed and running

Setup

  1. Clone the repository.
  2. Create database:
    CREATE DATABASE your_db_name;
    \c your_db_name
    \i init_db.sql
  3. Install dependencies:
    npm install express pg
  4. Configure environment: Create a .env file or set env vars:
    PG_USER=your_db_user
    PG_PASSWORD=your_db_password
    PG_DATABASE=your_db_name
    PG_HOST=localhost
    PG_PORT=5432
  5. Run server:
    node server.js

API Endpoints

Method Endpoint Description
GET /users Retrieve all users
GET /users/:id Retrieve user by ID
POST /users Create a new user
PUT /users/:id Update a user by ID
DELETE /users/:id Delete a user by ID

Example Requests

# Create user
curl -X POST http://localhost:3000/users \
  -H 'Content-Type: application/json' \
  -d '{"name":"Alice","email":"alice@example.com","age":30}'

# Get all users
curl http://localhost:3000/users

About

3mtt Mini Project: Store and Retrieve Data in PostgreSQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published