-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (25 loc) · 882 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
var express = require("express");
var app = express();
app.use(express.static('public'));
app.get('/:timestamp',function(req, res){
var timestamp = req.params.timestamp;
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
if(!isNaN(parseInt(timestamp))){
timestamp = parseInt(timestamp);
}
var date = new Date(timestamp);
if(date.getTime() > 0){
return(res.status(200).json({
unix: date.getTime(),
natural: months[date.getMonth()] + ' ' + date.getDate() + ' , ' + date.getFullYear()
}));
} else {
return(res.status(200).json({
unix: null,
natural: null
}))
}
});
app.listen(process.env.PORT || 3000, function(){
console.log('App started on port '+process.env.PORT);
});