Created
December 20, 2018 13:33
-
-
Save dennyjohnk/87502f95c362407696722ba6ba01d5a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
class MessageController { | |
/** | |
* GET / | |
* Renders Home page | |
* @param req Object | |
* @param res Object | |
* @param next Callback | |
*/ | |
getMessage(req, res, next) { | |
console.log(req); | |
res.send('Hello Worldsss!'); | |
} | |
postMessage(req, res, next) { | |
console.log(req.body); | |
res.send('gotcha!'); | |
} | |
} | |
exports.messageController = new MessageController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/** | |
* Module dependecy | |
*/ | |
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const check = require('check-node-version'); //check node version | |
const dotenv = require ('dotenv'); | |
const compression = require('compression'); | |
/** | |
* Load environment variables from .env file, where API keys and passwords are configured. | |
*/ | |
dotenv.config({ path: ".env" }); | |
/** | |
* Routes | |
*/ | |
const messageRouter = require('./routes/message-router'); | |
class App { | |
constructor() { | |
this.express = express(); | |
this.routes(); | |
this.middleware(); | |
this.launchConf(); | |
} | |
middleware() { | |
this.express.set("port", process.env.PORT || 4000); | |
this.express.use(bodyParser.urlencoded({ extended: true })); | |
this.express.use(bodyParser.json()); | |
} | |
routes() { | |
this.express.use("/", messageRouter.apiRouter); | |
} | |
launchConf() { | |
/** | |
* Start Express server. | |
*/ | |
this.express.listen(this.express.get("port"), () => { | |
// tslint:disable-next-line:no-console | |
console.log((" App is running at http://localhost:%d \ | |
in %s mode"), this.express.get("port"), this.express.get("env")); | |
// tslint:disable-next-line:no-console | |
console.log(" Press CTRL-C to stop\n"); | |
}); | |
} | |
} | |
exports.default = new App().express; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment