/rest-api-boilerplate

Rest API Boilerplate using typescript and express

Primary LanguageTypeScript

Rest API Boilerplate (Node.js, Express and Typescript)Build Status

This Rest API boiler plate was created using different "often used" technologies for example:

  • Node.js
  • Express
  • Typescript
  • Typegoose and Mongoose (ODM "Object Document Mapper")

TODO: Create generic repository pattern and remove last dependencies

  • MongoDB

I followed this tutorial in order to understand the functionality and logic of an Express Node Typescript application.

The application is divided by

  • Routes
  • Controllers
  • Models

That was intended to follow the MVC model represented in the following image:


Express Tutorial Part 4: Routes and controllers

image source: developer.mozilla.org


Start Application

Install dependencies using npm :

npm install

Create .env file in src with following variables :

  • MONGO_USER
  • MONGO_PASSWORD
  • DB_CONNECTION_STRING
  • DB_SERVER
  • PORT
  • JWT_SECRET

Example :

Mongodb connection URI:

mongodb://<mongodb_password>:<password>@mongodb0.example.com:27017/admin

MONGO_USER=<database_password>
MONGO_PASSWORD=<database_password>
DB_CONNECTION_STRING=mongodb://
DB_SERVER=@mongodb0.example.com:27017/admin
PORT=<desired_port>
JWT=<desired_jwt_secret>

Available scripts in package.json

Start server using nodemon as filewatcher on .ts files (with node command)

npm run dev

Start server without filewatcher (with node command)

npm run dev:start

Build application

npm run build

Clean application

npm run clean

Execute linter on application

npm run lint

Compile application

npm run tsc

Start server using nodemon as filewatcher on .ts files (with ts-node command)

npm run dev:typescript