-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
74 lines (59 loc) · 1.66 KB
/
app.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const express = require('express')
const path = require('path')
const app = express()
app.get('/', (req, res)=> {
var path = require('path');
res.sendFile(path.resolve('./index.html'));
})
app.get('/api/timezone=:tz(*)', (req, res)=> {
const tz = capitalizeFirstLetter(req.params.tz)
try{
let d = new Date().toLocaleString('en-US', {timeZone: tz});
d = d.split(', ')
let object = {
result: true,
date : d[0],
time : d[1]
}
res.send(object);
}
catch(error){
let object = {
result: false,
message: error.message
}
res.send(object)
}
})
app.get('/api', (req, res)=> {
try{
let d = new Date().toLocaleString('en-US', {timeZone: 'Asia/Kolkata'});
d = d.split(', ')
let object = {
result: true,
date : d[0],
time : d[1]
}
res.send(object);
}
catch(error){
let object = {
result: false,
message: error.message
}
res.send(object)
}
})
app.listen(process.env.PORT || 3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
function capitalizeFirstLetter(input){
input = input.toLowerCase()
let words = input.split('/')
let capitalize =[]
words.forEach(element => {
capitalize.push(element[0].toUpperCase() + element.slice(1, element.length))
});
let output =capitalize.join('/')
return output
}