Skip to content

Xenira/ts-express-template

Repository files navigation

Express Typescript Template with MongoDB and Passport

Simple template with support for MongoDB and Passport.

Why this template

This template gives you a fundation for developing REST APIs. The Project shoud help you getting started by providing a foundation on which you can extend.

Whats inside?
  • Express server setup for APIs

  • MongoDB connection

  • Basic user management

  • Input validation

Usage

Getting the template

Simply download the latest release from https://github.com/Xenira/ts-express-template/releases. Extract the archive and run yarn install or npm install from within the extracted folder.

Starting (With watcher)

yarn start or npm start

Building

yarn build or npm build

Environments

PORT

Sets the port the server binds to

Structure

The folder structure is as follows:

Folder Content Files

./src

Application source directory

app.ts

Initializes express and routing

index.ts

Starts the express application by binding to http(s)

./src/config

Helper objects and Middleware

passport.ts

Passport configuration and middleware

validation.ts

Middleware that rejects requests that didnt validate successfully

error.ts

This contains a small custom Error class to make creating an Error easyer

./src/controllers

Logic that is called from the router

example.controller.ts

Empty excample controller with handlers for every HTTP verb returning Im a teapot

user.controller.ts

Handlers for login and registration

./src/models

MongoDB connection and models

db.ts

Initializes database

user.model.ts

Base user model for login

./src/routes

Routes that can be importet in app.ts and call the controller logic

index.ts

Base router that handles login and registers other routers

user.ts

Excample controller for authorized access.

./src/public

Staticly accessable files

---

./sslcert

Place your certificates here

---

./config.json

Database and other config can be put here

---

./dist

Compiled JavaScript files (Only exists after build)

---