-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 692 Bytes
/
server.js
File metadata and controls
27 lines (22 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const express = require('express')
const app = express()
const path = require('path')
const moment = require('moment')
const port = process.env.PORT || 8080
app.listen(port, () => console.log('Example app listening on port ' + port) )
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'index.html')) )
app.get('/:query', (req,res) => {
var stamp
(/^\d{8,}$/.test(req.params.query)) ? stamp = moment(req.params.query, "X") : stamp = moment(req.params.query, "MMMM D, YYYY")
if(stamp.isValid()) {
res.json({
unix: stamp.format("X"),
natural: stamp.format("MMMM D, YYYY")
})
} else {
res.json({
unix: null,
natural: null
})
}
})