0.4.1 • Published 7 years ago

npts v0.4.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

npts

A minimal, modular TypeScript framework for creating and reusing NodeJS REST API Servers.

Travis

Usage

Creating a server

// src/server.ts

import * as npts from 'npts';

import AppModule from './modules/app-module';

const server = new npts.Server();

server.load({
    dbConnector: npts.Databases.MONGO,
    modules: [ AppModule ],
    port: 3000,
});

Creating a server automatically starts that server once all modules have been fully loaded.

Creating a Module

// src/modules/app-module/index.ts

import { AbstractModel, BaseModule, RouteInfo } from 'npts';
import * as express from "express";
import UserModel from './models/test-model';

export default class AppModule extends BaseModule {
    constructor() {
        super();
        
        this.addRoute(RouteInfo.RouteType.GET, '/', [this.index]);
    }
    
    public get Models(): Array<typeof AbstractModel> {
        return [ UserModel ];
    }
    
    public index(req: express.Request, res: express.Response, next: express.NextFunction) {
        res.send('hello world');
    }
}

Navigating to localhost:3000/ will now show 'hello world' in your browser!

Models

// src/modules/app-module/models/user-model.ts

import { AbstractModel } from 'npts';
import { auto, registerFields, uniq } from 'npts/metadata';

@registerFields(
    'id', 'name',
)
class TestModel extends AbstractModel {

    @uniq(true)
    @auto(true)
    public id: number;
    
    @uniq(true)
    get name(): string {
        return this._name;
    }
    
    private _name: string = 'test-model';
    
    constructor() {
        super();
        
        this.id = 1;
    }
}
0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago