Skip to content

kshitijv09/Nest.js-api

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

API using Nest.js, TypeORM, PostgreSQL, and JWT

This API is built using Nest.js, TypeORM, PostgreSQL, and JWT, providing various functionalities such as user signup, login, and CRUD operations for managing products. The API also includes unit testing files using Jest to ensure the reliability and stability of the application.

Features

  1. User Signup: Allows users to create a new account by providing a unique username and password.

  2. User Login: Enables users to authenticate and obtain a JSON Web Token (JWT) for accessing protected routes.

  3. Get All Products: Retrieves a list of all products available in the system.

  4. Get Single Product: Fetches details of a specific product using its unique identifier.

  5. Add Product: Allows authorized users to add new products to the database.

  6. Delete Product: Authorized users can delete products based on their unique identifiers.

  7. Update Product: Authorized users can update product information.

Prerequisites

Before running the API, ensure you have the following installed:

  • Node.js (at least version 12)
  • PostgreSQL database
  • npm or yarn (npm is included with Node.js)

Installation

  1. Clone the repository:
git clone https://github.com/your-username/your-repository.git
cd your-repository
  1. Install dependencies:
npm install
# or
yarn install
  1. Set up the database:

    • Create a new PostgreSQL database.
    • Configure the database connection settings in src/config/database.ts.
  2. Run Migrations:

npm run migration:run
# or
yarn migration:run

Usage

  1. Run the API:
npm run start:dev
# or
yarn start:dev
  1. The API will be accessible at http://localhost:3000 by default.

  2. Endpoints:

    • POST api/v1/auth/signup: Create a new user account.
    • POST api/v1/auth/login: Authenticate and receive a JWT token.
    • GET api/v1/products: Get all products (requires JWT token).
    • GET api/v1/products/:id: Get a specific product by its ID (requires JWT token).
    • POST api/v1/products: Add a new product (requires JWT token).
    • DELETE api/v1/products/:id: Delete a product by its ID (requires JWT token).
    • PATCH api/v1/products/:id: Update product information (requires JWT token).

Testing

The API comes with unit testing files using Jest to ensure its correctness. To run the tests:

npm run test
# or
yarn test

Security

Please note that this API uses JWT for authentication, and it's essential to handle and store JWT tokens securely to prevent unauthorized access.

Contributions

Contributions to the project are welcome! Feel free to open issues or submit pull requests for enhancements, bug fixes, or additional features.

License

This API is open-source and available under the MIT License.


Thank you for using our API! If you have any questions or need further assistance, please don't hesitate to contact us. Happy coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published