All Projects → bymi15 → express-typeorm-rest-boilerplate

bymi15 / express-typeorm-rest-boilerplate

Licence: MIT license
Boilerplate code to get started with building RESTful API Services (Express, TypeORM MongoDB stack)

Programming Languages

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

Projects that are alternatives of or similar to express-typeorm-rest-boilerplate

gobarber-api-gostack11
API GoBarber / NodeJS / Express / Typescript / SOLID
Stars: ✭ 39 (-26.42%)
Mutual labels:  jest, typeorm
nodejs-boilerplate
Clean Architecture for node.js projects (Typescript + Express + TypeORM + Typedi)
Stars: ✭ 199 (+275.47%)
Mutual labels:  typeorm, typedi
ng-nest-cnode
Angular 10 Front-End and Nestjs 7 framework Back-End build Fullstack CNode
Stars: ✭ 17 (-67.92%)
Mutual labels:  jest, typeorm
node-backend-template
A template for NodeJS backend projects
Stars: ✭ 19 (-64.15%)
Mutual labels:  jest, typeorm
typescript-boilerplate
A modern TypeScript project setup, for Node.js and browsers (using esbuild).
Stars: ✭ 502 (+847.17%)
Mutual labels:  jest
aws-nestjs-starter
Serverless, AWS, NestJS, GraphQL and DynamoDB starter
Stars: ✭ 200 (+277.36%)
Mutual labels:  jest
nodejs-vuejs-mysql-boilerplate
Node.js (REST API) + Vue.js/Nuxt.js (Frontend/Backend) + MySQL Boilerplate
Stars: ✭ 134 (+152.83%)
Mutual labels:  jest
vue-typedi
Use typedi injections in Vue components
Stars: ✭ 18 (-66.04%)
Mutual labels:  typedi
rescript-jest
ReScript bindings for Jest
Stars: ✭ 274 (+416.98%)
Mutual labels:  jest
Express-REST-API-Template
Minimal starter project for a Node.js RESTful API based off express generator
Stars: ✭ 26 (-50.94%)
Mutual labels:  jest
react-initial-bootstrap
an "almost complete" template for your new projects
Stars: ✭ 24 (-54.72%)
Mutual labels:  jest
ts-detox-example
Example TypeScript + React-Native + Jest project that integrates Detox for writing end-to-end tests
Stars: ✭ 54 (+1.89%)
Mutual labels:  jest
clean-architecture-api-boilerplate
A boilerplate for creating TypeScript APIs following the Clean Architecture principles.
Stars: ✭ 116 (+118.87%)
Mutual labels:  jest
ts-nextjs-tailwind-starter
🔋 Next.js + Tailwind CSS + TypeScript starter packed with useful development features
Stars: ✭ 880 (+1560.38%)
Mutual labels:  jest
opentelemetry-ext-js
js extensions for the open-telemetry project
Stars: ✭ 122 (+130.19%)
Mutual labels:  typeorm
sentry
👁 A self hosted dashboard to monitor servers and services.
Stars: ✭ 19 (-64.15%)
Mutual labels:  jest
coconat
🍥 StarterKit Builder for rocket-speed App creation on 🚀 React 17 + 📙 Redux 4 + 🚠 Router 5 + 📪 Webpack 5 + 🎳 Babel 7 + 📜 TypeScript 4 + 🚔 Linters 23 + 🔥 HMR 3
Stars: ✭ 95 (+79.25%)
Mutual labels:  jest
pg-error-enum
TypeScript Enum for Postgres Errors with no runtime dependencies. Also compatible with plain JavaScript.
Stars: ✭ 18 (-66.04%)
Mutual labels:  typeorm
ionic2-jest-example
Example of how to test an Ionic2 app with Jest
Stars: ✭ 43 (-18.87%)
Mutual labels:  jest
angularjs-jest
Testing AngularJS applications with Jest
Stars: ✭ 24 (-54.72%)
Mutual labels:  jest

Express TypeORM REST API Boilerplate

Quality Gate Status travis stackshare npm

Awesome boilerplate code to get started with building RESTful API Services!
Typescript with NodeJS and Express as well as MongoDB integration with TypeORM
JSON Web Tokens (JWT) based User Authentication,

TypeDI dependency injections, testing with Jest, and a bunch more.
Made with ❤️ by Brian Min


Why?

The main reason I decided to start this project is to provide a boilerplate for the NodeJS, Express, Typescript, TypeORM, MongoDB stack. Also with TypeORM, this boilerplate code can easily be modified to use MySQL, PostGreSQL, and many more. Tedious setting up of project structure, logging, testing, env and eslint is all done for you! Now you can focus on actually implementing the core functionalities and not spending hours setting up and configuring your project.

Try it out and feel free to raise any issues or create pull requests if you would like to contribute!

Features

  • JWT based user authentication with jsonwebtoken and express-jwt.
  • Dependency Injection with TypeDI.
  • ORM with support for many databases (MySQL, PostgreSQL, MariaDB, SQLite, MongoDB, and more) with TypeORM.
  • Clear and organised structure with different layers such as entities, services, middlewares, loaders, etc.
  • Validation thanks to class-validator.
  • Unit and Integration Testing with Jest.
  • Security Features with Helmet.
  • Role-based access control using a custom-built middleware.
  • Simple Data Seeding with custom-built factories and Faker.js.
  • Code generator for entity, service, route, factory, seed, test with a custom-built generator script and CLI tool Commander.

Getting Started

Step 1: Set up the Development Environment

Install Node.js and NPM

Install a MongoDB server or use MongoDB Atlas

Step 2: Create a new project

Fork or download this project and modify package.json for your new project.

Make a copy of the .env.example file and rename it to .env.

Create a new database and add the connection string in the .env file.

Install the required packages.

npm install

This installs all the dependencies with NPM.

Now your development environment should be ready to use!

Step 3: Serve your application

Go to the root directory and start your app with this npm script.

npm run dev

This starts a local server using nodemon and ts-node. The server base endpoint will be http://127.0.0.1:3000 where 3000 is the PORT variable you set in the .env file.

Scripts and Tasks

Install

  • Install all dependencies with npm install

Linting

  • Run code syntax and format checking using npm run lint which runs eslint.
  • Automatically fix lint errors with npm run lint:fix.

Running MongoDB locally

For this step you need to install MongoDB Server

  • Run npm run mongodb to start a local MongoDB server with it's data stored in .mongodb in the root directory.
  • This is very useful for unit / integration testing.
  • It's always a good idea to use a separate database for testing.

Tests

  • Run unit tests using npm run test (for Windows users) or npm run test:unix (for Mac and Linux users).

Running the app in development

  • Run npm run dev to start nodemon with ts-node.
  • The server base endpoint will be http://127.0.0.1:3000 where 3000 is the PORT variable you set in the .env file.

Building and running the app in production

  • Run npm run build to compile all the Typescript sources and generate JavaScript files.
  • To start the built app located in build use npm start.

API Routes

The route prefix is /api by default, but you can change this in the .env file.

Route Description
/api Base endpoint
/api/auth/login Auth - login endpoint
/api/auth/register Auth - register endpoint
/api/user Example entity endpoint - returns all users
/api/user/current Example entity endpoint - returns current logged in user
/api/company Example entity endpoint - returns all companies
/api/company/:id Example entity endpoint - returns a company by id
/api/jobApplication Example entity endpoint - returns all job applications
... ...

Project Structure

Name Description
.mongodb/ Local MongoDB server data
build/ Compiled source files will be placed here
commands/ Custom CLI command tools used with npm scripts
src/ Source files
src/api/middlewares/ Custom middlewares
src/api/entities/ TypeORM Entities (Database models)
src/api/services/ Service layer
src/config/ The configuration file which loads env variables
src/database/factories Factories generate entities with mock data
src/database/seeds Seeds use factories to save mock data in the database
src/loaders/ Loader is where the app is configured and database is loaded
src/types/ *.d.ts Custom type definitions
test *.spec.ts Unit and integration tests
.env.example Environment configurations

Logging

For logging we use winston.

License

MIT

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].