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)) get(res, true) }) module.exports = router;