Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.
/ ts-framework Public archive

A simple Typescript abstraction layer over Express and Mongoose.

License

Notifications You must be signed in to change notification settings

devnup/ts-framework

Repository files navigation

ts-framework

Build Status   Coverage Status

A minimalistic framework for typescript based applications, with async/await and decorators support.

DEPRECATION NOTICE

This repository contains the v1 track for the TS Framework, which is now deprecated.

For an updated version checkout the v2 tree on nxtep-io/ts-framework fork.



Getting Started

Installing in your repository

# Install using Yarn
yarn add git+https://github.com/devnup/ts-framework.git#GIT_REV_HASH 

# Install using NPM
npm install --save git+https://github.com/devnup/ts-framework.git#GIT_REV_HASH 

TL;DR - A single file server

Configure a new Server instance and start listening on desired port.

import Server, { Logger, BaseRequest, BaseResponse } from 'ts-framework';

// Define a sample hello world route
const SampleRoutes {
  '/': async (req: BaseRequest, res: BaseResponse) => {
    res.success({ message: 'Hello world!' });
  }
}

// Define the server configuration
const server = new Server({
  port: process.env.PORT as any || 3000,
  routes: {
    get: SampleRoutes,
  },
});


// Startup the simple server
server.listen()
  .then(() => Logger.info(`Server listening on port: ${server.config.port}`))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

You can also check a full project seed in the Examples directory of this repository.

Usage Guide

Follow the Usage Guide for the basic boilerplate and a sample project configuration with Database and user authentication samples.

Internal components:

  • Logger (backed by winston)
  • Database (backed by Mongoose)
  • Router (backed by Express)
    • Controllers: Classes for handling API calls with decorators and async/await support
    • Filters: Middlewares for body validation, permission handling and other interception routines
    • Responses:: Simple wrappers over res.status(code).json(result) for success and error responses.

External components available as built-in middlewares:

  • OAuth 2.0 (express-oauth2-server)
  • Sentry (RavenJS)
  • CORS (express/cors)
  • Multipart (express/multer)
  • User Agent (express-useragent and request-ip)
  • Body Parser (express/body-parser)
  • Method Override (express/method-override)
  • Cookie Parser (express/cookie-parser)

Other external plugins and middlewares for this framework

  • ts-framework-versioning

    Handles API versioning using HTTP Headers.

  • ts-framework-notification

    Handles transactional notifications using SMTP (email templates) and Firebase Messaging (push notifications).

  • ts-framework-migration

    Advanced usage plugin for handling Schema migrations safely within production environments.

  • ts-framework-sockets

    Socket.io layer over the TS-Framework. Currently in public alpha.

  • ts-framework-queue (coming soon)

    Redis based task rotation queue services. Currently in closed alpha.

  • ts-framework-cache (coming soon)

    Redis based cache services for performance. Currently in closed alpha.

  • ts-framework-sql (coming soon)

    MySQL / Postgres database layer based on Sequelize. Currently in closed alpha.

Documentation

Checkout the rendered TS Docs in the official page: https://devnup.github.io/ts-framework/

To generate the Typedoc reference of the available modules directly from source, run the following command:

yarn run docs

Then check the documentation at ./docs/index.html.

License

The project is licensed under the MIT License.