All Projects → rootstrap → node-ts-api-base

rootstrap / node-ts-api-base

Licence: other
REST API boilerplate made with Express + NodeJS

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to node-ts-api-base

Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+30427.59%)
Mutual labels:  typeorm
lynx
Opinionated Framework built on top of NestJS and TypeORM
Stars: ✭ 44 (-49.43%)
Mutual labels:  typeorm
nest-convoy
[WIP] An opinionated framework for building distributed domain driven systems using microservices architecture
Stars: ✭ 20 (-77.01%)
Mutual labels:  typeorm
Prime
✨Open Source GraphQL CMS
Stars: ✭ 1,675 (+1825.29%)
Mutual labels:  typeorm
nestjs-api-mongoose
Collection example apps with NestJS and Typeorm, Sequelize, Mongodb, PostgreSQL, MySQL, GraphQL, Mercurius, etc. for the NestJS community 😻
Stars: ✭ 153 (+75.86%)
Mutual labels:  typeorm
bookshelf
My GraphQL playground
Stars: ✭ 64 (-26.44%)
Mutual labels:  typeorm
nest-boilerplate
Nest.js boilerplate with CircleCI, Commitizen, Commitlint, Docker-Compose, ESLint, GitHub Actions, Husky, Lint-staged, OpenAPI, Prettier, PostGreSQL, Travis CI, TypeORM
Stars: ✭ 16 (-81.61%)
Mutual labels:  typeorm
server
Core server in the Alkemio platform, offering a GraphQL api for interacting with the logical domain model.
Stars: ✭ 20 (-77.01%)
Mutual labels:  typeorm
nestjs-api-example
NestJS Example
Stars: ✭ 60 (-31.03%)
Mutual labels:  typeorm
uni-pushy-server
upushy 热更新后端。https://upushy.yoouu.cn/
Stars: ✭ 30 (-65.52%)
Mutual labels:  typeorm
Domain Driven Hexagon
Guide on Domain-Driven Design, software architecture, design patterns, best practices etc.
Stars: ✭ 4,417 (+4977.01%)
Mutual labels:  typeorm
MyAPI
A template to create awesome APIs easily ⚡️
Stars: ✭ 117 (+34.48%)
Mutual labels:  typeorm
typeorm-uml
Generate Entity Relationship diagrams for Typeorm powered projects.
Stars: ✭ 207 (+137.93%)
Mutual labels:  typeorm
Nestjs Realworld Example App
Exemplary real world backend API built with NestJS + TypeORM / Prisma
Stars: ✭ 1,838 (+2012.64%)
Mutual labels:  typeorm
nest-rest-typeorm-boilerplate
🍱 backend with nest (typescript), typeorm, and authentication
Stars: ✭ 142 (+63.22%)
Mutual labels:  typeorm
Mili
mili 是一个开源的社区系统,界面优雅,功能丰富😛
Stars: ✭ 2,875 (+3204.6%)
Mutual labels:  typeorm
serverless-nestjs-typeorm
Example how to nestjs using the serverless framework with TypeORM
Stars: ✭ 99 (+13.79%)
Mutual labels:  typeorm
prime-nestjs
A production-ready NestJS boilerplate using Typescript, Postgres, TypeORM, and Docker.
Stars: ✭ 140 (+60.92%)
Mutual labels:  typeorm
Wern-Fullstack-Template
React, Next.js, MaterialUI, Styled-Components, TypeGraphQL, URQL, ApolloServer (express), TypeORM, PostgreSQL, Node.js, TypeScript
Stars: ✭ 173 (+98.85%)
Mutual labels:  typeorm
sf-midway-admin
🚀 基于MidwayJs + TypeScript + TypeORM + Redis + MySql + Vue2 + Element-UI编写的一款简单高效的前后端分离的权限管理系统
Stars: ✭ 93 (+6.9%)
Mutual labels:  typeorm

Node-TS-Api-Base

This project includes the boilerplate for a basic rest-api made in Node.JS with Express + Typescript.

Basic Requirements

  1. Install Node.js (lts-version v14.16.0)
  2. Install yarn if not present curl -o- -L https://yarnpkg.com/install.sh | bash (macOS and generic Unix environments)
  3. Install required dependencies by yarn
  4. cp .example.env .env.dev
  5. cp .example.env.test .env.test
  6. Create your DB (i.e. psql for Postgres: psql -U <user> -h <host> -c "create database <db name>;") with same name as your .env file.
  7. Run ENV=[dev, test, prod] yarn db:setup.
  8. Start your server with ENV=[dev, prod] yarn dev.

Some scripts

Add ENV=[dev, prod] before running scripts. Why?: Configuration file used by Typeorm

Run yarn build to build js from typescript source.

Run yarn start to start the server from the compiled folder (/dist).

Run yarn test to run tests.

Run yarn dev to start and automatically detect any source-code changes, restarting the server as well.

Run yarn typeorm schema:drop to drop your schema of the DB.

Run yarn typeorm schema:sync to resync the schema of your DB.

Run yarn seed:run to run seed files.

Run yarn db:reset to drop schema and re run it, then seed the DB.

Run yarn typeorm migration:generate -n <migration's name> to create a new migration.

Run yarn typeorm migration:run to run pending migrations.

Run yarn typeorm migration:revert to rollback migrations.

Run yarn typeorm migration:show to see the list of all migrations (pending and also ran).

Github Actions

Our CI workflow is based on Github Actions, for this, we need to set several secret keys for integrated with some services like SonarQube or databases for example. To configure these keys in the GitHub repo, you can follow the next guideline. Also, for configuring the SonarQube keys you can follow the next steps.

Action Secret Key
Password for the database that is used in the testing step TEST_POSTGRES_PASSWORD
URL of SonarQube server SONAR_URL
Key of the project on the SonarQube server SONAR_PROJECT_KEY
Token generated of the project in the SonarQube server SONAR_TOKEN

Running with Docker

Prerequisites

In order to run the app with Docker, you should install or update to the latest version, we recommend to install Docker-Desktop due to composer and some cool CLI-UI tools are included.

Development with Docker

The following commands will build and run all you need to start working on the base, without any other installation requirements. Important: if you already have postgres running locally, you'll need to kill the service before run docker-compose up.

docker-compose --env-file .env.dev build
docker-compose --env-file .env.dev up

Deployment with Docker (only for production)

The following commands will build and run a Docker image ready for production and size-optimized.

Build Docker image

docker build -f Dockerfile.prod -t node-ts-api-base .

Run docker image (you need to add .env file as param)

docker run --rm --env-file=.env.prod -p 3000:3000 --name node-api node-ts-api-base

Fix issue at build docker image (dependencies to install bcrypt are not providede in alpine version of node)

Add the following line before the command RUN yarn in the Dockerfile.

RUN apk --no-cache add --virtual builds-deps build-base python

Debugging

If you're using VSCode, you can run the API in debug mode by clicking on Debug > Start Debugging or with the shortcut F5. This will start the app in DEV mode and then you can add as many breakpoints as you need.

API Documentation

After running the server you will find OpenAPI Specification here: http://<host>:<port>/docs

App scaffolding

This is the suggested scaffolding for this project. You can take a look at:

.
├── __tests__
│   └── ...
├── src
│   ├── config
│   │   └── ...
│   ├── controllers
│   │   └── ...
│   ├── database
│   │   └── ...
│   ├── entities
│   │   └── ...
│   ├── interfaces
│   │   └── ...
│   ├── services
│   │   └── ...
│   ├── utils
│   │   └── ...
│   ├── views
│   │   └── ...
│   ├── app.ts            (App root and is where the application will be configured.)
│   ├── server.ts         (HTTP server)
├── README.md
├── .nvmrc                (Locks down your Node version.)
├── jest.config.js        (Jest configuration file.)
├── yarn-lock.json
├── package.json          (Your application’s package manifest.)
├── tsconfig.json         (The TypeScript project configuration.)
├── prod-path.js          (Tool used to run in production, translates ts-path and alias)

Dependencies

  • routing-controllers - Create structured class-based controllers with decorators usage in Express.
  • routing-controllers-openapi - Runtime OpenAPI v3 schema generation for routing-controllers.
  • swagger-ui-express - Serves auto-generated swagger-ui API docs from express.
  • typeorm - NodeJS ORM.
  • nodemon - Utility that will monitor for any changes in your source and automatically restart your server.
  • multer - NodeJS middleware for handling multipart/form-data.
  • tsconfig-paths - Utility to register relative paths set at tsconfig file
  • express-rate-limit - Basic rate-limiting middleware used to limit repeated requests to public APIs
  • morgan - HTTP request logger middleware for node.js
  • nodemailer - Module for Node.js to allow the easy email sending.

Code Quality

This repo is integrated with SonarQube for static code analysis and test coverage reporting. This guide covers all the steps, including how to run the test coverage on a local machine. Use the provided sonar-project.properties as-is. Once that is covered:

  1. Run yarn test:cover to run tests with coverage reporting.
  2. Run sonar-scanner to import the test results into the sonar dashboard.

Docs

Express documentation Typescript documentation

Credits

Express API Base is maintained by Rootstrap with the help of our contributors.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].