A simple Express.js API built with TypeScript and PostgreSQL database support.
- Node.js (v18 or higher)
- Docker and Docker Compose
- npm or yarn
npm install
Start the PostgreSQL database using Docker Compose:
docker compose up -d
This will start:
- PostgreSQL database on port 5432
The .env
file is already configured with default values:
- Database:
os_assignment_db
- Username:
postgres
- Password:
password123
- Host:
localhost
- Port:
5432
Development mode (with hot reload):
npm run dev
Production mode:
npm run build
npm start
GET /health/db
- Database connection health checkGET /users
- Get all usersPOST /users
- Create a new user (requiresname
andemail
in request body)
The database is automatically initialized with a users
table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
curl http://localhost:3000/users
curl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "john@example.com"}'
curl http://localhost:3000/health/db
Start the database:
docker-compose up -d
Stop the database:
docker-compose down
View logs:
docker-compose logs postgres
Connect to PostgreSQL directly:
docker exec -it os-assignment-postgres psql -U postgres -d os_assignment_db