@tiscode/node-base

TISCODE Base Module for NodeJS Applications

Usage no npm install needed!

<script type="module">
  import tiscodeNodeBase from 'https://cdn.skypack.dev/@tiscode/node-base';
</script>

README

TISCODE Node Base

Version Releases

Version: v0.2.1

  • Hotfix cannot set headers after they are sent

Version: v0.2.0

  • ExpressAuthenticatedHandler with jsonwebtoken
  • ExpressPublicHandler
  • Handlers must implement handle method

Version: v0.1.0

  • HttpServer app with peer support for graphql
  • Http Event Types
  • Express adapter (for Handler constructor and Command Factory constructor)
  • Express default handler and abstract handler
  • Command and Command Factory abstracts
  • iif helper function
  • ifnull helper function

Installation

npm i @tiscode/node-base or yarn add @tiscode/node-base

Usage

How to use ExpressAuthenticatedHandler?
With node-base for direct routes ( post / put / get / delete / patch / all )
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = new App.Http.Server();

app.on('started', () => {
  app.attachRouter({
    path: '/my-endpoint',
    method: 'post', // you can change this to 'put', 'get', 'delete', 'patch' or 'all'
    router: expressAuthenticatedHandler
  });
});

app.listen(3000);
With node-base for use routers
import { Router } from 'express';
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = new App.Http.Server();
const router = Router();

router.post('/my-endpoint', expressAuthenticatedHandler);

app.on('started', () => {
  app.attachRouter({
    path: '/api', // default is '/'
    method: 'use',
    router: expressAuthenticatedHandler
  });
});

app.listen(3000);
With express
import express from 'express';
import { App } from '@tiscode/node-base';
import MyCommandFactory from './factories/commands/my-command';

const expressAuthenticatedHandler = App.Http.Express.adapter(App.Http.Express.authenticatedHandler, MyCommandFactory);
const app = express();
app.post('/my-endpoint', expressAuthenticatedHandler);

app.listen(3000);