Skip to content

This project is a simple yet complete RESTful API built using Node.js, TypeScript, and PostgreSQL. It simulates an electronic product database for a fictional store, providing a single route for creating products. The API is designed with scalability in mind, includes testing with Jest and Supertest, and is fully documented using Swagger.

Notifications You must be signed in to change notification settings

habidbesp/rest-api-node-typescript-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API with Node.js, TypeScript & PostgreSQL

This project is a simple yet complete RESTful API built using Node.js, TypeScript, and PostgreSQL. It simulates an electronic product database for a fictional store, providing a single route for creating products. The API is designed with scalability in mind, includes testing with Jest and Supertest, and is fully documented using Swagger.

Project Links

Features

  • Express.js server built with TypeScript.
  • PostgreSQL as the database for storing electronic products.
  • API endpoints to create products in the database.
  • Swagger documentation for easy API exploration.
  • Jest and Supertest tests for API endpoint validation.
  • Deployed and accessible via Render.

Example Endpoints:

  • GET /api/products: Retrieve all products in the store.
  • POST /api/products: Create a new product in the store.
  • PUT /api/products/:id: Update a product by its ID.
  • PATCH /api/products/:id: Update de property "availability".
  • DELETE /api/products/:id: Delete a product by its ID.

Visit the Swagger UI to explore and test all the endpoints interactively.

Installation (Optional)

  • Node.js (>=16.x)

  • PostgreSQL

    Steps

  1. Clone the repository:
  git clone https://github.com/habidbesp/rest-api-node-typescript-server.git

  cd rest-api-node-typescript-server
  1. Install dependencies:
  npm install
  1. Create a .env file in the root directory with the following variable (adjust as needed for your environment):
  DATABASE_URL=your_postgresql_database_url
  1. Run the development server:
  npm run dev

This will start the server with Nodemon, and the API will be available at http://localhost:4000.

API Documentation

  • The API is fully documented using Swagger. You can access the documentation by navigating to:

      http://localhost:4000/docs

    This will open the Swagger UI, where you can explore the available endpoints.

Testing

To run tests with Jest and Supertest:

npm run test

To run tests with coverage:

npm run test:coverage

This will execute the tests and provide a detailed coverage report.

Technologies Used

  • Node.js and Express for the server.
  • TypeScript for type safety and development efficiency.
  • PostgreSQL as the database.
  • Sequelize ORM for interacting with the database.
  • Swagger UI and Swagger JSDoc for API documentation.
  • Jest and Supertest for testing.
  • dotenv for environment variable management.

Future Plans

A frontend application for this API is currently in development using React and TypeScript. The frontend will provide a user-friendly interface to interact with the product data and enhance the functionality of this server. Stay tuned for updates!

License

This project is licensed under the ISC License

About

This project is a simple yet complete RESTful API built using Node.js, TypeScript, and PostgreSQL. It simulates an electronic product database for a fictional store, providing a single route for creating products. The API is designed with scalability in mind, includes testing with Jest and Supertest, and is fully documented using Swagger.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published