Author: Erick Salangsang
Version: 1.0.0
A simple API for managing users using Express.js v5.x and TypeScript.
- Clone the repository:
git clone https://github.com/yourusername/users-api.git
- Go into the project folder:
cd users-api
- Install dependencies:
npm install
- Create a
.envfile based on.env.example:
cp .env.example .env
- Update the
.envfile with your values: You'll need a running PostgreSQL instance. The easiest way is via Docker (see below), or install PostgreSQL locally.
API_PORT=8081
CLIENT_URL=http://localhost:3000
POSTGRES_HOST=localhost
POSTGRES_PORT=5433
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
POSTGRES_DB=your_database_name
The users table is created automatically on startup if it doesn't already exist.
- Start the server in development mode:
npm run dev
Server will run on the port specified in .env (default: 8081).
- Type-check the project:
npm run typecheck
- Build and start the compiled app:
npm run build
npm start
This spins up both the API and a PostgreSQL database:
docker compose up --build
The API will be available on the port specified by API_PORT (default: 8081), and PostgreSQL data persists in a named Docker volume. PostgreSQL itself is reachable on the host at POSTGRES_PORT (default: 5433) to avoid clashing with other local Postgres instances.
GET /users– Get all usersGET /users/:id– Get a user by IDPOST /users– Add a new userPUT /users/:id– Update a userDELETE /users/:id– Delete a user
ISC License