Giter VIP home page Giter VIP logo

typeix's Introduction

Typescript framework for Node.js

Build Status npm version

Features

  • Dependency Injection - partial JSR 330 standard
  • Modular design
  • MVC structure
  • Component driven -> singletons -> depends on injection level
  • Request Filters
  • Nice routing features -> supports static && dynamic routing && reverse router
  • Controller inheritance

Getting started

create project

npm init
npm install typeix --save
npm install @types/node --save

create controllers/core.controller.ts

import { Controller, Action, isPresent } from "typeix";
import { readFile } from "fs";
import { normalize } from "path";

@Controller({
  name: "core" // route controller
})
export class CoreController {

  @Action("favicon") // route action
  async faviconLoader() {
    return await <Promise<Buffer>> new Promise(
      (resolve, reject) =>
        readFile(
          normalize(__dirname + "/pathto/my/favicon.ico"),
          (err, data) => isPresent(err) ? reject(err) : resolve(data)
        )
    );
  }

  @Action("index")
  myIndexAction() {
    return "Hello world"; // accepts - string // buffer // Promise<string|Buffer>
  }
}

create application.module.ts

import { Module, Router, Logger, Inject, IAfterConstruct, Methods } from "typeix"
import { CoreController } from "./controllers/core.controller"

@Module({
  controllers: [CoreController],
  providers: [Logger, Router]
})
class Application implements IAfterConstruct {
  
  @Inject(Router)
  private router: Router;
  
  afterConstruct() {
    // just controller/action always points to root module
    this.router.addRules([
        {
          methods: [Methods.GET],
          // module/controller/action or controller/action
          route: "core/favicon", 
          url: "/favicon.ico"
        },
        {
          methods: [Methods.GET],
           // equals root/core/index since bootstrap module is root module
          route: "core/index",
          url: "/"
        }
    ]);
  }
  
}

create bootstrap.ts

import {Application} from "./application.module";
import {httpServer} from "typeix";

/**
 * Bootstrap http or https server.
 *
 * @description
 * Creates server instance on port 9000
 * We always use separate bootstrap file to bootstrap application 
 * because of testing or server side fakeHttp feature.
 * We will be able to simulate server side request with fakeHttp
 */
httpServer(Application, 9000);

To start your application run node bootstrap.js after compiling to javascript.

Typeix Munich node user group 2017.03.23

Typeix MNUG 2017.03.23

<< back

typeix's People

Contributors

gkopevski avatar igorzg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.