token-server-tools v0.0.11
token-server-tools
Some basic tools to be used within ExpressJS server.
Install
npm install --save token-server-toolsUsage
HttpUtil
HttpUtil.Methods
This returns an object of basic HTTP Request Methods, to use within HttpUtil.request.
HttpUtil.response(res, status, data)
This method returns a basic response object of following structure;
{
res: res,
status: status,
data: data
}HttpUtil.request(method, url, headers, body)
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 bodyare 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
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'
})
}PasswordUtil
PasswordUtil.generatePassword()
Generates Base58 encoded, 8 character length password.
const PasswordUtil = require('token-server-tools').PasswordUtil
function exampleFunction(){
const randomPassword = PasswordUtil.generatePassword()
console.log(randomPassword)
}PasswordUtil.generateBasicAuth()
Generates Base64 encoded, basic auth token.
const PasswordUtil = require('token-server-tools').PasswordUtil
function exampleFunction(){
const authToken = PasswordUtil.generateBasicAuth()
console.log(authToken)
}ResponseUtil
ResponseUtil.RtnType
Returns an object of response codes, to use within ResponseUtil.response.
ResponseUtil.response(code, description)
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)
}