var TimeProcessor = require('./timeprocessor').TimeProcessor; const Messaging = require('./messaging').Messaging; class TimestampAPI { /* Custom paths used for the API. */ #paths = { "conversion": "/:date" } /* Create the time stamp with direct access to the Express instance. @param {Express} instance - The Express instance */ constructor(instance) { this[`instance`] = instance; // your first API endpoint... instance.get("/api/hello", function (req, res) { res.json({greeting: 'hello API'}); }); this.conversion(); } /* Handle conversion requests. */ conversion() { [`/api`, `/api${this.#paths["conversion"]}`].forEach((PATH) => { [`get`, `post`].forEach((METHOD) => { this[`instance`][METHOD](PATH, (REQUEST, RESPONSE) => { try { let RESPONSE_DATA = TimeProcessor.convert((Object.keys(REQUEST.params).length ? REQUEST.params.date : false) ? REQUEST.params.date : (new Date()).toUTCString()); RESPONSE.json(RESPONSE_DATA); } catch(ERROR) {Messaging.exception(RESPONSE, ERROR)} }) }) }) } } module.exports = {TimestampAPI}