express-base-server
TypeScript icon, indicating that this package has built-in type declarations

1.0.14 • Public • Published

Base Express Server

This is simple express server wrote on TypeScript and you also can write on TypeScript

// Inject class
class InjectMe {
    public greet() {
        console.log('Inject say you Hello!');
    }
}

//  Class for one of express apps
class FirstApp {
    public $inject: Array<string> = ['injectMe'];
    public parent: any;

    //  Call before server will be started
    Begin(injectMe: InjectMe) {
        injectMe.greet();

        this.parent.get(this, '/', this.home);
        this.parent.post(this, '/testPost', this.testPost);
    }

    //  Home page function
    public home(req: any, res: any) {
        res.end("Hello! It is home page!");
    }

    //  Test POST request
    public testPost(req: any, res: any) {
        console.log('Post');
        let response: Object = {msg: 'Hello, POST!', name: req.body.name};

        res.end(JSON.stringify(response));
    }
}

let app: Mes_BaseServer = new Mes_BaseServer();
app.AddDependency('injectMe', new InjectMe());
app.AddApp(FirstApp);
app.StartServer();
  • InjectMe - injected class.
  • FirstApp - one app of express server. You can create more than one app added then by call app.AddPpp.
  • AddDependency(dependency_name, dependency_object) - add dependency with name. Dependencies list in app add to $inject property.
  • AddApp(your_app_class) - add app.

Use webpack && node app/main.ts for run project.

Package Sidebar

Install

npm i express-base-server

Weekly Downloads

13

Version

1.0.14

License

ISC

Last publish

Collaborators

  • mes_studio