Giter VIP home page Giter VIP logo

acdl-rest-api's Introduction

Build

Resti

This is a simple NodeJs Typescript Rest API using MVC design pattern. It uses MongoDB as the database and ExpressJs as the web framework.

Production API

Base URL: https://resti.markapiado.com

Documentaion: https://documenter.getpostman.com/view/4071486/2s9YXk5224

Rate Limit:: 100 requests per minute both for authenticated and unauthenticated users. This is to prevent abuse and to ensure the availability of the API for everyone.

Features

  • Typescript
  • MongoDB, ExpressJs, NodeJs stack
  • MVC design pattern
  • Consistent coding style with Prettier and ESLint
  • High cohesion between components and modules
  • Pre-commit hooks with Husky
  • Operating system-agnostic scripts
  • CI/CD with Github Actions
  • Docker containerization

Installation

Clone the repository using the command below.

https://github.com/markAPIado/acdl-rest-api.git

Run the following command to install the dependencies.

npm install

Environment Variables: Rename the rename.env file to .env and update the environment variables.

cp rename.env .env

For Windows users, you can use the following command instead.

copy rename.env .env

Git Initialize the git repository and set the remote origin. Note: You cannot run npm run husky:prepare if you have not initialized the git repository. You do not need to do this if you cloned the repository.

git init

Husky

Run the following command to set up the pre-commit hooks. The default npm run prepare script will cause issues on Docker containerization so we need to use a different script.

npm run husky:prepare

Development

Run the following command to start the development server.

npm run dev

Pre-commit Workflow

Run the command below to lint and format the code before committing. This will avoid prettier and eslint making changes to the code format on the pre-commit hook.

npm run local:pre-commit

Commit Changes to Git

This will run the pre-commit hook created by Husky before committing the changes to git. Stages are as follows:

  • lint using eslint
  • format using prettier
  • test using jest

NOTE: You want to skip the test stage if it takes too long to run. However, it is recommended to run the tests before committing the changes to git.

Build

Run the following command to compile the code to dist folder.

npm run build

Production

Run the following command to start the production server.

npm start

Testing

Run the test once using the command below.

npm test

Run the test in watch mode using the command below.

npm run test:watch

Run the test coverage using the command below.

npm run test:coverage

Clustering using PM2

Check the ecosystem.config.js file for more details. Install PM2 globally if you haven't done so.

npm install pm2 -g

Run the following command to start the production server using PM2.

npm run cluster:start

Other Scripts

Formatting:

  • npm run format - formats the code using prettier.
  • npm run format-check - checks the format of code using prettier.

Linting:

  • npm run lint - identifyies and reports on patterns found in ECMAScript/JavaScript code.

Cleaning up

  • npm run clean - removes the dist, coverage, and node_modules folders.

Postman Collection

Import the RESTI Collections.postman_collection.json file to Postman to test the API endpoints.

acdl-rest-api's People

Contributors

markapiado avatar

Watchers

 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.