• Stars
    star
    2,831
  • Rank 16,067 (Top 0.4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone. ⭐️ Star to support our work!

Ts.ED logo


Build & Release PR Welcome Coverage Status npm version semantic-release code style: prettier github opencollective

Website   •   Getting started   •   Slack   •   Twitter

A Node.js and TypeScript Framework on top of Express. It provides a lot of decorators and guidelines to write your code.

What it is

Ts.ED is a Node.js and TypeScript Framework on top of Express/Koa.js. Ts.ED is a framework on top of Express/Koa to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.

Features

  • Use our CLI to create a new project https://cli.tsed.io
  • Support TypeORM, Mongoose, GraphQL, Socket.io, Swagger-ui, Passport.js, etc...
  • Define class as Controller,
  • Define class as Service (IoC),
  • Define class as Middleware and MiddlewareError,
  • Define class as Json Mapper (POJ to Model and Model to POJ),
  • Define root path for an entire controller and versioning your Rest API,
  • Define as sub-route path for a method,
  • Define routes on GET, POST, PUT, DELETE and HEAD verbs,
  • Define middlewares on routes,
  • Define required parameters,
  • Inject data from query string, path parameters, entire body, cookies, session or header,
  • Inject Request, Response, Next object from Express request,
  • Template (View),
  • Testing.

Links

Getting started

See our getting started here to create new Ts.ED project or use our CLI

Overview

Server example

Here an example to create a Server with Ts.ED:

import {Configuration, Inject} from "@tsed/di";
import {PlatformApplication} from "@tsed/common";
import "@tsed/platform-express";
import cookieParser from "cookie-parser";
import compress from "compress";
import methodOverride from "method-override";

@Configuration({
  port: 3000,
  middlewares: ["cookie-parser", "compression", "method-override", "json-parser", "urlencoded-parser"]
})
export class Server {}

To run your server, you have to use Platform API to bootstrap your application with the expected platform like Express.

import {$log} from "@tsed/common";
import {PlatformExpress} from "@tsed/platform-express";
import {Server} from "./Server";

async function bootstrap() {
  try {
    $log.debug("Start server...");
    const platform = await PlatformExpress.bootstrap(Server);

    await platform.listen();
    $log.debug("Server initialized");
  } catch (er) {
    $log.error(er);
  }
}

bootstrap();

To customize the server settings see Configure server with decorator

Controller example

This is a simple controller to expose user resource. It use decorators to build the endpoints:

import {Inject} from "@tsed/di";
import {Summary} from "@tsed/swagger";
import {
  Controller,
  Get,
  QueryParams,
  PathParams,
  Delete,
  Post,
  Required,
  BodyParams,
  Status,
  Put,
  Returns,
  ReturnsArray
} from "@tsed/common";
import {BadRequest} from "@tsed/exceptions";
import {UsersService} from "../services/UsersService";
import {User} from "../models/User";

@Controller("/users")
export class UsersCtrl {
  @Inject()
  private usersService: UsersService;

  @Get("/:id")
  @Summary("Get a user from his Id")
  @Returns(User)
  async getUser(@PathParams("id") id: string): Promise<User> {
    return this.usersService.findById(id);
  }

  @Post("/")
  @Status(201)
  @Summary("Create a new user")
  @Returns(User)
  async postUser(@Required() @BodyParams() user: User): Promise<User> {
    return this.usersService.save(user);
  }

  @Put("/:id")
  @Status(201)
  @Summary("Update the given user")
  @Returns(User)
  async putUser(@PathParams("id") id: string, @Required() @BodyParams() user: User): Promise<User> {
    if (user.id !== id) {
      throw new BadRequest("ID mismatch with the given payload");
    }

    return this.usersService.save(user);
  }

  @Delete("/:id")
  @Summary("Remove a user")
  @Status(204)
  async deleteUser(@PathParams("id") @Required() id: string): Promise<User> {
    await this.usersService.delete(user);
  }

  @Get("/")
  @Summary("Get all users")
  @Returns(200, Array).Of(User)
  async findUser(@QueryParams("name") name: string) {
    return this.usersService.find({name});
  }
}

Contributors

Please read contributing guidelines here.

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

The MIT License (MIT)

Copyright (c) 2016 - 2022 Romain Lenzotti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

ts-gphoto2-driver

📷 A Node.js wrapper for libgphoto2 written in TypeScript. Useful for remote controlling of DSLRs and other digital cameras supported by gphoto2.
TypeScript
76
star
2

logger

📄 A multi channel logger written in TypeScript.
TypeScript
61
star
3

tsed-cli

💻 CLI for Ts.ED framework
TypeScript
42
star
4

ts-httpexceptions

🚦 See https://tsed.io/docs/exceptions.html
TypeScript
25
star
5

tsed-example-typeorm

Open issue or PR to https://github.com/TypedProject/tsed
TypeScript
23
star
6

tsed-getting-started

The official Ts.ED getting started example
TypeScript
20
star
7

tsed-formio

Repository dedicated to formiojs.
TypeScript
14
star
8

tsed-example-vuejs

TypeScript
13
star
9

tsed-example-mongoose

TypeScript
12
star
10

tsed-example-react

TypeScript
11
star
11

tsed-example-aws

TypeScript
11
star
12

gflow

🛠️ A better `git flow`
JavaScript
9
star
13

example-ts-express-decorator

TsExpressDecorators examples
8
star
14

tsed-example-socketio

TypeScript
7
star
15

vuepress-theme-tsed

A vuepress theme for tsed.io
Vue
7
star
16

ts-json-properties

Use typescript decorator to retrieve a property from properties.json and load it on class attribute.
TypeScript
6
star
17

tsed-example-passportjs

TypeScript
5
star
18

tsed-example-oidc

Project example with Ts.ED and OIDC provider
JavaScript
5
star
19

tsed-monorepo-utils

🛠️ A tool to build and publish packages (Typescript or Javascript) on npm for projects based on mono repository (lerna).
JavaScript
4
star
20

tsed-api

API application for the official Ts.ED website.
TypeScript
4
star
21

tsed-example-prisma

TypeScript
3
star
22

tsed-example-passport-azure-ad

TypeScript
2
star
23

tsed-swagger-example

TypeScript
2
star
24

ts-doc

Generate documentation over TypeScript code for vuepress
JavaScript
2
star
25

tsed-passport-jwt-example

TypeScript
2
star
26

tsed-example-session

TypeScript
1
star
27

tsed-example-graphql

TypeScript
1
star
28

v5.tsed.io

HTML
1
star
29

tsed-engines

Template engine consolidation library. Inspired from consolidate.js
TypeScript
1
star
30

tsed-commands-generate-swagger

TypeScript
1
star
31

tsed-example-webpack

TypeScript
1
star
32

tsed-vite-workspaces

A repository that show you how to create mono repository with Ts.ED and Vite/React.
TypeScript
1
star
33

tsed-monorepo-template

A monorepository template to create project based on Monorepo utils, lerna and yarn workspaces
JavaScript
1
star
34

tsed-vite-plugin-ssr-example

Project with Ts.ED and Vite-plugin-ssr
TypeScript
1
star