Utility
Logging
#There are three types of logging function for general information, warning message and error message respectively.
[log|info](message) | warn(message) | error(error_object)
#message
String message passed to logging.
error_object
Error object raised by system.
Example
#exports.add = sqlseries((db, payload) => [
cb => {
log(payload)
cb()
},
db.updateInsert(null, payload.id, 'contact', payload)
])
cb => {
log(payload)
cb()
},
db.updateInsert(null, payload.id, 'contact', payload)
])
Information displayed in console as follows:
>> 26/10 12:28:53 [anonymous] /api/crud-api/contact/add
info: crud-api/contact.js:24:9 < database.js:30:15 < database.js:47:9 < dispatch.js:178:39
>>
{
"id": "261d31f5-3435-4da4-ab22-93142eb61f16",
"name": "Peter Pan",
"email": "peter@gamil.com",
"gender": "male"
}
Lodash
#The Lodash library is included by default.
Others
#capitalize(word)
#Convert the first character to uppercase.
parse(string)
#Converting string to JSON object with error logging. Return null when error occurs.
isInvalid(object)
#Check the object if it is undefined or is empty or is null.