-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (32 loc) · 867 Bytes
/
server.js
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
var express = require("express");
var app = express();
var path = require("path");
var moment = require("moment");
app.use(express.static(__dirname + '/public'));
app.get('/', function(req,res){
res.end();
});
app.get('/:time', function(req,res){
var unixtime, date, naturaldate;
if (Number.isInteger(+req.params.time)){
unixtime = +req.params.time;
date = moment(unixtime * 1000);
} else {
date = moment(req.params.time);
unixtime = date.format('x') / 1000;
}
naturaldate = date.format('MMMM DD, YYYY');
if (!date._isValid) {
unixtime = null;
naturaldate = null;
}
var result = {
unix: unixtime,
natural: naturaldate
}
res.end(JSON.stringify(result));
});
app.listen(process.env.PORT || 8080, function(err,log){
if (err) throw err;
console.log('Server running on port: '+ process.env.PORT);
});