This is a simple CRUD API that allows users to create, read, update and delete user data. The user data consists of a user's name, email and password. The API is built using Node.js, Express.js, node-postgres and TypeScript.
- Node.js
- Express.js
- TypeScript
- Postgres
- Users
- id: number
- name: string
- email: string
GET /users/- Get all usersGET /users/:id- Get a user by idPOST /users/- Create a new user- Sample request Body:
{ "name": "John Doe", "email": "john.doe@example.com" }
- Sample request Body:
PUT /users/:id- Update a user by id- Sample request Body:
/users/1 { "name": "Jerry Smith", "email": "jerry.smith@example.com" }
- Sample request Body:
DELETE /users/:id- Delete a user by id
- Node.js
- TypeScript
- Postgres
- Postman
- pnpm (optional but recommended)
- Clone the repository
- Install the dependencies
pnpm install
- Make sure you have a Postgres database running with the following schema: (Use pgAdmin or postbird to create the database and table)
CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL );
- Insert some sample data into the
userstableINSERT INTO users (name, email) VALUES ('Jerry', 'jerry@example.com'); INSERT INTO users (name, email) VALUES ('Tom', 'tom@example.com');
- Ensure the database connection details are correct in the
src/db/index.tsfile. - Run the server
pnpm start
- Test the API endpoints using Postman. Use postman collection user-crud-v1.
- Add authentication and authorization
This project was realized with the help of the following resources: