@novice1/app
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

@novice1/app

Create Express applications.

Installation

$ npm install @novice1/app

Usage

const routing = require('@novice1/routing'),
  { FrameworkApp } = require('@novice1/app');

// Router
const router = routing().get('/', (req, res) => {
  // ...
}).put('/', (req, res) => {
  // ...
});

// FrameworkApp
const app = new FrameworkApp({
  framework: {
    // middlewares
    middlewares: [
      (req, res, next) => {
        next();
      }
    ],
    // authorization middlewares
    auth: [
      (req, res, next) => {
        next();
      }
    ],
    // validation middlewares
    validators: [
      (req, res, next) => {
        next();
      }
    ]
  },
  // routers
  routers: [
    router
  ]
});

// http.Server
const server = app.listen(8000, '0.0.0.0', () => {
  console.log('Application started ...');
  console.log(app.meta)
});

addOptions

Concatenate current application options with new options.

app.addOptions({
  // add more routers
  routers: [router]
});

Routing

app.addRouters([router]);
app.get({
  path: '/index',
  name: 'Home',
  tags: ['Index']
}, function homepage(req, res) {
  // ...
});

app.put('/add', (req, res) => {
  // ...
});

app.use((err, req, res) => {
  // ...
});
const lazyRouter = app.lazyrouter();
lazyRouter.get({
  path: '/index',
  name: 'Home',
  tags: ['Index']
}, function homepage(req, res) {
  // ...
});

lazyRouter.put('/add', (req, res) => {
  // ...
});

lazyRouter.use((err, req, res) => {
  // ...
});

http ServerOptions

const httpServerOptions = {};

const server = app.build(httpServerOptions);
server.listen(8000, '0.0.0.0', () => {
  console.log('Application started ...');
  console.log(app.meta)
});
const https = require('https');
const httpsServerOptions = {};

const server = app.build(httpsServerOptions, https);
server.listen(8000);

References

Readme

Keywords

none

Package Sidebar

Install

npm i @novice1/app

Weekly Downloads

4

Version

0.3.2

License

MIT

Unpacked Size

61 kB

Total Files

17

Last publish

Collaborators

  • demingongo