-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (48 loc) · 1.66 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const app = express();
const cors = require('cors');
const mongoose = require('mongoose');
const patientsRouter = require('./routes/patients');
const doctorsRotuer = require('./routes/doctors');
const appointmentRouter = require('./routes/appointments');
require('dotenv').config();
app.use(express.json());
app.use(cors(
{
origin: "*", // allow the server to accept request from different origin
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
credentials: true // allow session cookie from browser to pass through
}
));
app.use('/patients', patientsRouter);
app.use('/doctors', doctorsRotuer);
app.use('/appointments', appointmentRouter);
const port = process.env.PORT || 5000;
let uri = '';
process.env.NODE_ENV === 'test' ? uri = process.env.ATLAS_URI_TEST : uri = process.env.ATLAS_URI;
mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true, useFindAndModify: false }, (err) => {
if (!err) {
console.log("Connection to database successful!");
}
});
function getCurrentTime() {
const date = new Date()
console.log(date)
}
function getEndDateTime(dateTime) {
// 2021-03-22T09:00:00
const hrs = (parseInt(dateTime.split('T')[1].split(':')[0]) + 1).toString().padStart(2, '0')
const time = hrs + ':00:00'
const date = dateTime.split('T')[0]
return date + 'T' + time
}
app.listen(port, () => {
console.log(`Listening on port ${port}`)
console.log(`NODE_ENV = ${process.env.NODE_ENV}`)
getCurrentTime()
getEndDateTime("2021-03-22T09:00:00")
})
app.get('/', (req, res) => {
res.status(200).json("Hello");
})
module.exports = app;