-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (31 loc) · 941 Bytes
/
server.js
File metadata and controls
42 lines (31 loc) · 941 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var express = require('express'),
app = express(),
moment = require("moment");
app.use('/', express.static('public'));
app.get('/:date', function(req, res){
var date = req.params.date;
var unix = null;
var natural = null;
if(+date >= 0){
unix = +date;
natural = toNatural(unix);
}
if(isNaN(+date) && moment(date, "MMMM D, YYYY").isValid()){
unix = toUnix(date);
natural = toNatural(unix);
}
var toObj = { "unix": unix, "natural": natural };
res.send(JSON.stringify(toObj));
});
function toNatural(unixDate){
return moment.unix(unixDate).format("MMMM D, YYYY");
}
function toUnix(natDate){
return moment(natDate, "MMMM D, YYYY").format("X");
}
app.use(function(req, res) {
res.status(404).end('(404) Opps, seems you have got a little lost!');
});
app.listen('8080', function(){
console.log('Now listening on port 8080!');
});