diasonline-utils v1.0.1
diasonline-utils
Utils package to provide standardised code and methods to all nodejs applications
required environment variables
- REDIS_HOST
- REDIS_PORT
- REDIS_PASSWORD
- REDIS_TLS_SERVER
- REDIS_CHANNEL
- LOG_ORIGIN
- DATABASE_HOST
- DATABASE_PORT
- DATABASE_USERNAME
- DATABASE_PASSWORD
- DATABASE_NAME
writeLog()
This package exports a function to write logs and requires following parameters. It also requires the LogType enum to use as type
- logType: should be one the values of the enum LogType. The LogType enum is also exported.
- message: the actual message of the log
- info: optional info field
- sessionInfo: optional object that can contain the information about a session. That object can contain a userId, customerId and/or environmentId
WebServer
The webserver class export a constructor and a start function.
constructor(port, routes)
the constructor requires the port it has to run on and an array of routes following the IRoute interface
start()
the start function inits the webserver and activates all routes and middlewares.
IRequestHandler
This interface shows how a handler should be constructed.
IRoute
This interface shouws how a route should be constructed.
MethodType
This enum returns the possble route methods. GET, POST, PUT and DELETE.
getGlobalConnection
If a function would need a connection to the global database, this is how to get it.
getConnectionByKey
If a function would need to open een connection based on the database key, this is how to get it.
request based connection
If the webserver detects the database key in the path (query) or body of a request, it will try to open a connection to that database and store the connection in the body of the req object. To use the connection just get it from req.body.connection
Versions
- 1.0.1: first deployed version
4 years ago