Giter Club home page Giter Club logo

ecomm's Introduction

User Management API

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.

Installation

  1. Clone this repository.
  2. Run npm install to install the necessary dependencies.
  3. Create a PostgreSQL database.
  4. 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>
  1. Run npm run start to start the server.

Usage

User Endpoints

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
}

Error Responses

The API returns the following error responses:

400 Bad Request

Returned when the client sends an invalid request. The response body will contain a JSON object with an error message.

401 Unauthorized

Returned when the client is not authorized to access a resource. The response body will contain a JSON object with an error message.

404 Not Found

Returned when the requested resource cannot be found. The response body will contain a JSON object with an error message.

500 Internal Server Error

Returned when an unexpected error occurs on the server. The response body will contain a JSON object with an error message.

Testing

To run the unit tests, run the command npm run test. This will run all tests in the __tests__ directory.

License

This project is licensed under the MIT License.

ecomm's People

Watchers

Mahmoud Elshafaey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.