var express = require('express');
var bodyParser = require('body-parser')
var app = express();
var low = require('lowdb');
var db = low('db.json');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
db.defaults({ secrets: [] }).write();
app.get('/', function (req, res) {
res.sendFile(__dirname + "/views/index.html");
});
app.post('/secret', function (req, res) {
var newSecret =
db.get('secrets')
.push(req.body.secret)
.write();
var secret =
db.get('secrets')
.sample()
.value();
res.send({secret:secret});
});
app.listen(3000, function () {
console.log("伺服器跑起來啦!在你的瀏覽器網址列輸入 localhost:" + 3000 + " 吧!");
});