express-base-server
v1.0.14
Published
This is simple express server wrote on **TypeScript** and you also can write on *TypeScript*
Downloads
29
Maintainers
Readme
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.