ts-site-starter
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

ts-site-starter

npm license github-issues

nodei.co

travis-status stars forks

forks

Features

  • Configure express application.
  • Written in TS

Usage

lib/app-routes.ts

const siteStarter = require('tsm.name');
 
import {AppResponse, BasicRoutes} from 'ts-site-starter';
import {Request} from 'express';
 
export class AppRoutes extends BasicRoutes {
  constructor(basePath: string) {
    super(basePath);
    this.addRoutes();
  }
 
  homePage(req: Request, res: AppResponse) {
    res.serve('home', {});
  }
 
  addRoutes() {
    this.router.get('/', this.homePage.bind(this));
  }
}

index.ts

import * as express from "express";
import * as log from 'great-logs';
import { configureRest, serverConfig } from 'ts-site-starter';
import { AppRoutes } from './lib/app-routes';
 
/**
 * The server.
 * @class Server
 */
export class Server {
 
  public app: express.Application;
 
  /**
   * Constructor.
   * @class Server
   * @constructor
   */
  constructor() {
    //create expressjs application
    this.app = express();
    configureRest(this.app, express);
  }
 
  routeApp() {
    const routes = (new AppRoutes('')).getRoutes();
    this.app.use(routes);
  }
 
  start() {
    this.routeApp();
    const port = serverConfig.getPort();
    this.app.listen(port, function () {
      log.info('port: %s', port);
      log.info('url: %s', serverConfig.base);
    });
  }
}
 
// Start the application
new Server().start();

Install

npm install --save ts-site-starter

Scripts

  • npm run build : rm -rf dist && tsc
  • npm run dev : npm run build:all && node dist/index.js
  • npm run test : mocha ./dist/test/*.js

Dependencies

Package Version Dev
@types/cookie-parser ^1.4.1
@types/cookies ^0.7.1
@types/express ^4.11.1
@types/html-minifier ^3.5.2
@types/mkdirp ^0.5.2
@types/node ^10.0.4
args-finder 0.0.3
body-parser ^1.18.2
cookie-parser ^1.4.3
cookies ^0.7.1
ejs ^2.6.1
express ^4.16.3
great-logs 0.0.4
html-minifier ^3.5.15
mkdirp ^0.5.1
path ^0.12.7
@types/chai ^4.1.3
@types/mocha ^5.2.0
@types/source-map ^0.5.7
chai ^4.1.2
mocha ^5.1.1
source-map ^0.7.2

Contributing

Contributions welcome; Please submit all pull requests against the master branch. If your pull request contains TypeScript patches or features, you should include relevant unit tests. Please check the Contributing Guidelines for more details. Thanks!

Author

Wendly Saintil wendlysaintil@gmail.com https://twitter.com/wendlysaintil

License

Readme

Keywords

Package Sidebar

Install

npm i ts-site-starter

Weekly Downloads

1

Version

0.0.7

License

MIT

Unpacked Size

34 kB

Total Files

40

Last publish

Collaborators

  • wendly