Reference
Last updated: 4 - 5 - 2019

Zinky

Zinky is the server class

Properties

PropertyDescription
portThe port on which the server should listen
aliasesObject to replace modules names in routes
staticModuleNameThe special module name that serves global static content
staticFolderThe folder that contains global static content
logRequestDateWhether to log request date in console or not
stopPugLayoutIf true, ZinkyJS will not use pug-layout. This requires a render function
modulesObject containing app modules
mdsSame as modules

Methods

MethodParametersDescription
addHook(hook(req, res, next))
  • hook: The hook to add. It takes the famous req, res and next as arguments.
Adds a global hook
addHookFromModule(module, 'method')
  • module: The module from which the hook is taken..
  • method: A string containing the method taken as hook..
Adds a global hook from a module. Keeps the module scope in the hook.
listen(#port)
  • port: port on which to listen. Default: The existent app port
listens for connections on the given port
loadModules()Load(or reload) all app modules to modules property
catcher({req}, {res})
  • req: req object found in every hook.
  • res: res object found in every hook.
Catches all errors in hooks and operations
render(..args)
  • ...args: Parameters are completely customizable.
Defines the way views are rendered

Constructor

new Zinky({options}), where options is an object with the following properties:

PropertyTypeDefault
portINTEGER, STRING3000
aliasesOBJECT{'aliase': 'moduleName'}{}
staticModuleNameSTRINGfile
staticFolderSTRINGpublic
logRequestDateBOOLEANfalse
stopPugLayoutBOOLEANfalse
catcherFUNCTIONLogs error and responds it
renderFUNCTIONRenders views using pug-layout

Zinko

Zinko is the most basic module class

Properties

PropertyDescription
appThe app instance passed in initialization
clientFolderThe folder that contains the module's static content
dirnameThe path to directory where module's index.js is located
viewsFolderThe folder that contains the module's views

Methods

MethodParametersDescription
constructor(dirname, app)
  • dirname: The path to directory where module's index.js is located.
  • app: The app instance.
Module's constructor
v(viewName)Return a module's view by its name(without extension)
GET_file(req, res)This method is a default operation created in Zinko, that responds with a file after looking for it in clientFolder

req

The req object represents the HTTP request passed as first argument in every hook and operation. Here are the properties added to it by ZinkyJS:

Properties

PropertyDescription
actionRequested action name
appApp object
ipRequest client IP address
methodRequest method
moduleNameRequested module name
moduleRequest module
operationFunction name that will be called on this request
paramsRequest params
queryParsed request query string
urlRequest URL

res

The res object represents the HTTP response that an ZinkyJS app sends when it gets an HTTP request. Here are the methods added to it by ZinkyJS:

Methods

MethodParametersDescription
clearCookies()Deletes all cookies.
clearOneCookie('name')
  • name: Cookie name..
Deletes one cookie.
contentType('contentType')
  • contentType: content type..
Sets the HTTP content-type for the response.
cookie('name', val, {options})
  • name: Cookie name..
  • val: Cookie value..
  • option: HTTP Cookie directives: domain encode expires httpOnly maxAge path sameSite secure.
Sets a cookie.
deliver(#status, 'response')
  • status: Status code..
  • response: String body response..
Sends the response with the given HTTP status.
download('filePath')
  • filePath: Path to file..
Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download.
json({obj})
  • obj: JSON object to send..
Responds with JSON object (with the correct content-type).
redirect('location')
  • location: Redirection url.
Redirects to the given URL.
reload()Redirects back to the URL specified in the Referer header.
render(pugLayout.Page view, {locals}, pugLayout.Layout layout*)
  • view: The view to render.
  • locals: Data passed to view.
  • layout: Layout extended by view. (optional).
Responds with rendered view.
sendAsFile('content', 'ext')
  • content: Content to transfer..
  • ext: File Extension..
Transfers the given content as file. Sets the Content-Type response HTTP header field based on the given extension.
sendFile('filePath')
  • filePath: Path to file..
Transfers the file at the given path. Sets the Content-Type response HTTP header field based on the filename’s extension.
status(#code)
  • code: Status code..
Sets the HTTP status for the response.