fw-node
v1.0.4
Published
NodeJS server framework
Downloads
2
Readme
fw-node
An express-based node framework that wraps all api endpoints with a controller that handles response and errors.
Installation
Using npm: $ npm install fw-node
Using yarn: $ yarn add fw-node
Using pnpm: $ pnpm add fw-node
Usage
Once the package is installed, you can import two functions using import approach:
import { createFramework, createEndpoint } from 'fw-node'
Framework:
A new framework can be created in the following way:
createFramework function can receive the following parameters in the first arg:
| parameter | type |description | | ------------ | ------------ |----------- | | port | number |express listening port | | name | string |name of your service basically used for logs | | logLevel | debug, info, warning, error| level of logs to print | |jsonLimitSize| string | express json limit|
createFramework receive array of routes in the second arg
Endpoints:
A new endpoint can be created in the following way:
createFramework function can receive the following parameters:
| parameter | type |description | | ------------ | ------------ |----------- | | name | string |name of your service basically used for logs| | execute | (request: any, response: any) => Promise | endpoint entry function | | normalizeData | (data: any) => any |manipulate data that your execute function return before return it with the response| | headers | {[key: string]: string} |add some headers to the response | | withOwnResponse | boolean |if TRUE - return the response from the endpoint itself instead of the wrapper controller (false by default)|
Routes:
you can create new route in the following way:
you can also create new route with middleware in the following way: