Some basic tools to be used within ExpressJS server.
npm install --save token-server-tools
This returns an object of basic HTTP Request Methods, to use within HttpUtil.request
.
This method returns a basic response object of following structure;
{
res: res,
status: status,
data: data
}
This method creates a request instance with the given parameters, then returns the response of that request of structure of HttpUtil.response
. The parameter method
can be specified using HttpUtil.Methods
.
The parameters headers
and body
are optional.
const HttpUtil = require('token-server-tools').HttpUtil;
async function exampleFunction() {
const response = await HttpUtil.request(HttpUtil.Methods.GET, 'https://jsonplaceholder.typicode.com/posts')
console.log(response)
}
ConsoleLog
is based on the logger Winston
. Specify the type of the log and pass the log message as the first parameter. You can pass a second parameter to indicate the information of from where the log is printed.
const ConsoleLog = require('token-server-tools').ConsoleLog
function exampleFunction(){
ConsoleLog.info('Example Log Message', {
function: 'readme/exampleFunction'
})
}
Generates Base58 encoded, 8 character length password.
const PasswordUtil = require('token-server-tools').PasswordUtil
function exampleFunction(){
const randomPassword = PasswordUtil.generatePassword()
console.log(randomPassword)
}
Generates Base64 encoded, basic auth token.
const PasswordUtil = require('token-server-tools').PasswordUtil
function exampleFunction(){
const authToken = PasswordUtil.generateBasicAuth()
console.log(authToken)
}
Returns an object of response codes, to use within ResponseUtil.response
.
Returns a response object of following structure;
{
code: code,
desc: description
}
const ResponseUtil = require('token-server-tools').ResponseUtil
function exampleFunction(){
const exampleResponse = ResponseUtil.response(ResponseUtil.RtnType.Success, "A Successful Response")
console.log(exampleResponse)
}