This is a Node.js REST API built with Express, TypeScript, and PostgreSQL that allows users to create, read, update, and delete user accounts, as well as register and login to the application.
- Clone this repository.
- Run
npm install
to install the necessary dependencies. - Create a PostgreSQL database.
- Create a .env file in the root of the project and add the following environment variables:
DB_HOST=<database host>
DB_PORT=<database port>
DB_USER=<database user>
DB_PASSWORD=<database password>
DB_DATABASE=<database name>
JWT_SECRET=<JWT secret key>
- Run
npm run start
to start the server.
GET /users
Get a list of all users.
GET /users/:id
Get a single user by ID.
POST /users
Create a new user.
PUT /users/:id
Update an existing user.
DELETE /users/:id
Delete a user by ID.
Authentication Endpoints
POST /register
Create a new user account.
Request body:
{
"name": string,
"email": string,
"password": string
}
POST /login
Authenticate a user.
Request body:
{
"email": string,
"password": string
}
Response body:
{
"token": string
}
The API returns the following error responses:
Returned when the client sends an invalid request. The response body will contain a JSON object with an error message.
Returned when the client is not authorized to access a resource. The response body will contain a JSON object with an error message.
Returned when the requested resource cannot be found. The response body will contain a JSON object with an error message.
Returned when an unexpected error occurs on the server. The response body will contain a JSON object with an error message.
To run the unit tests, run the command npm run test
. This will run all tests in the __tests__
directory.
This project is licensed under the MIT License.