-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (35 loc) · 1.08 KB
/
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
//
// # SimpleServer
//
// A simple chat server using Socket.IO, Express, and Async.
//
var express = require('express');
var app = express();
var moment = require('moment');
var path = require('path');
//
// ## SimpleServer `SimpleServer(obj)`
//
// Creates a new instance of SimpleServer with the following options:
// * `port` - The HTTP port to listen on. If `process.env.PORT` is set, _it overrides this value_.
//
app.use(express.static(path.join(__dirname,'public')));
app.get('/:date',function(req,res){
var out = {
unix: null,
natuaral: null
}
if(!isNaN(req.params.date)){
out.unix = +req.params.date;
out.natuaral = moment(+(req.params.date)*1000).format('MMMM DD, YYYY');
}
else if(!isNaN(Date.parse(req.params.date))){
// var date = moment(req.params.date,'MMMM DD, YYYY');
out.unix =moment(req.params.date,'MMMM DD, YYYY').format('X');
out.natuaral = req.params.date;
}
res.send(out);
})
app.listen(process.env.PORT || 3000, function(){
console.log("Chat server listening at "+process.env.PORT);
});