-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
43 lines (33 loc) · 833 Bytes
/
server.js
File metadata and controls
43 lines (33 loc) · 833 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
'use strict';
const express = require('express'),
app = express(),
port = process.env.PORT || 8080;
app.get('/', function(req, res) {
res.send({"unix": null, "natural": null});
});
app.get('/:date', function (req, res) {
var date = isNaN(Number(req.params.date)) ?
new Date(req.params.date) :
new Date(Number(req.params.date)*1000);
res.send({ "unix" : date.getTime()/1000, "natural" : formatDateString(date)});
});
app.listen(port, function () {
console.log('Timestamp app listening on port ' + port + '.');
});
function formatDateString(date) {
var months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
return months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear();
}