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 installStart the PostgreSQL database using Docker Compose:
docker compose up -dThis 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 devProduction mode:
npm run build
npm startGET /health/db- Database connection health checkGET /users- Get all usersPOST /users- Create a new user (requiresnameandemailin 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/userscurl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "[email protected]"}'curl http://localhost:3000/health/dbStart the database:
docker-compose up -dStop the database:
docker-compose downView logs:
docker-compose logs postgresConnect to PostgreSQL directly:
docker exec -it os-assignment-postgres psql -U postgres -d os_assignment_db