1.0.3 • Published 9 months ago
thillais-backend-utils v1.0.3
Private utils package for Thillais Analystical Solution Private Limited
This package was created by using winston, winston-daily-rotate-file, axios, https, joi, fs, oracledb, redis, pg, multer, path, date-fns, crypto-js, crypto npm packages
Installation
npm install thillais-backend-utils
Usage
We have to mention the below configurations in the config file or it will get the took the default values
Logger:
config:
SERVER_LOG_FILENAME
SERVER_LOG_DATEFORMAT
SERVER_LOG_MAXSIZE
SERVER_LOG_MAXFILES
SERVER_LOG_LEVEL
APP_LOG_FILENAME
APP_LOG_DATEFORMAT
APP_LOG_MAXSIZE
APP_LOG_MAXFILES
APP_LOG_LEVEL
usage:
we can use the below exports to log them,
#level - info, debug, error
#message - whatever we wanted to print it in the respective log
serverLogger --> this will be print the log into the server log, we can use this as below example
example: serverLogger.{level}(message);
applicationLogger --> this will be print the log into the application log, we can use this as below example
example: applicationLogger.{level}(message);
serverLoggerMiddleware --> this will be print the log into the server log, we can use this as below example
example: pass this as a middleware function it will print info level logs, if we set SERVER_LOG_LEVEL as debug it will print the complete request, response payloads
serviceStartLog --> this will be print the log into the application log, we can use this as below example
example: serviceStartLog('functionName');
serviceFinishLog --> this will be print the log into the application log, we can use this as below example
example: serviceFinishLog('functionName');
return:
no returns
Axios:
No config required
usage:
we can use the below service like below.
sendRequestViaAxios --> (method, endpoint, requestPayload, headerConfig, certConfig)
methods as 'GET' or 'POST'
endpoint as your end-url
requestPayload as JSONObject or Parameters
headerConfig --> default header value set as '{ headers:{'Content-Type': 'application/json'} }', if you want to change or add you can send the object in the below structure.
{ headers:{'key' : 'value'}}
certConfig --> default header value set as '{ certPath: null, keyPath: null, caPath: null, rejectUnauthorized: false }', if you want to change or add you can send the object in the below structure.
{ certPath: 'cert_location', keyPath: 'key_location', caPath: 'ca_location', rejectUnauthorized: 'false/true' }
return:
{
statusCode,
responseData
}
Crypto:
config:
PG_ENC_KEY
PG_IV
usage: