snapplibs v1.0.35
Snapplibs is a simple and fast common functionality library for node.js services:
/ The snapplibs library provides the common functionality to the SNAPP application. The developers can able to install the package from the SNAPP nexus library and they will consume e below functions /
1. logger
2. dateFormat
3. utcDateFormat
4. easternDateFormat
5. errorResponse
6. successResponse
7. badRequest
8. unAuthorized
9. forbidden
10. insernalServer
```js
const {
logger,
dateFormatCCoE,
utcDateFormat,
easternDateFormat,
errorResponse,
successResponse,
badRequest,
unAuthorized,
forbidden,
insernalServer
} = require('snapplibs');
```
installation
```bash
npm install snapplibs
(or)
npm install snapplibs --save
(or)
npm install snapplibs --save-dev
```
Functions Implementation
Logger
In this library we are integrated as a bunyan framework. It is the CCoE approved library and it will return the logs as a JSON format followed by the CCoE patterns.
```js
const {logger} = require('snapplibs');
const obj = {
name : 'SNAPP',
version : 1.0.0
}
logger.info('Welcome to SNAPP Library', obj);
logger.error('SNAPP error messages');
logger.warn('Warning messages');
logger.debug('Debug messages');
logger.trace('Tracing messages');
```
Example output:
```bash
SNAPP INFO '{
"name": "SNAPP",
"hostname": "VDC1ITWB00019",
"pid": 11576,
"level": "info",
"msg": "Welcome to snapplibs { name: 'SNAPP', version: 1.0.0 }",
"time": "2022-02-10 19:39:21",
"src": {
"file": "C:\\Users\\z64525\\Nodejs\\Test code\\index.js",
"line": 14,
"func": "hai"
},
"v": 0,
"_timeStamp": "2022-02-10T19:39:21+05:30",
"logTransactionID": "b19dd267-f1f9-48e7-9d39-1c6a67323f6f"
}'
```
------------------------------ ****************** -------------------------------------------
Date Format
In the date format we are used into the moment framework Here we are developed below date formats
1. dateFormatCCoE - CCoE pattern
2. utcDateFormat - UTC date and time formater
3. easternDateFormat - US Eastern date and time formater
```js
** CCoE Pattern **
const {dateFormatCCoE} = require('snapplibs');
const date = dateFormatCCoE(new Date()); // The parameter should be a optional either user can pass or itshould be in empty. If it is a empty parameter the time will taken into the server time.
Example output : 2022-02-10T19:39:21+05:30
const date = dateFormatCCoE();
or
const date = dateFormatCCoE('2022-02-10');
----------------------------------------
** UTC Pattern **
const {utcDateFormat} = require('snapplibs');
const date = utcDateFormat(new Date()); // Date parameter should be in optional.
Example output : 2022-02-10T14:09:21Z
const date = utcDateFormat();
or
const date = utcDateFormat('2022-02-10');
------------------------------------------
** US Eastern pattern - This will converting into the UTC to US Eastern Zone **
const {easternDateFormat} = require('snapplibs');
const date = easternDateFormat(new date()); // Date parameter should be in optional.
Example output : 2022-02-10T09:09:21Z
const date = easternDateFormat();
or
const date = easternDateFormat('2022-02-10');
```
--------------------------------- ******* ------------------------------------
Response Structure
In the response structures we are handles the error and success scenarios.
/**
* The success response should be either Object or Array of Object format.
*/
```js
** Success Response **
const {successResponse} = require('snapplibs');
const response = [
{
key1 : value1,
key2 : value2
}
]
successResponse(response);
or
const responseObj = {
key1 : value1
key2 : value2
};
successResponse(responseObj);
Example output:
{
"key1" : "value1"
"key2" : "value2"
}
** Error Response **
const {errorResponse} = require('snapplibs');
const errorObj = {
status : 404,
error : [
statusCode : 404,
message : "Data not found"
]
}
errorResponse({status:400, message:"Data not found"});
Example output:
{
"status" : 404,
"error" : [
"statusCode" : 404,
"message" : "Data not found"
]
}
const {
badRequest,
unAuthorized,
forbidden,
insernalServer
} = require('snapplibs');
badRequest();
unAuthorized();
forbidden();
insernalServer();
```
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago