message-me/routes/index.js

24 lines
511 B
JavaScript
Raw Normal View History

const express = require('express');
const router = express.Router();
const fs = require('fs')
const file = './messages'
const get = (res, thankYou) => {
res.render('index', { title: 'Message Sage 😎', thankYou });
}
/* GET home page. */
router.get('/', function(req, res, next) {
get(res, false)
});
router.post('/', (req, res) => {
const log = { message: req.body.message, timestamp: new Date() }
fs.appendFileSync(file, JSON.stringify(log) + '\n')
get(res, true)
})
module.exports = router;