-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (32 loc) · 1.04 KB
/
index.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
require('dotenv').config({ path: './.env' });
// Importing Node Modules
const express = require('express');
const cors = require('cors');
// Importing File Dependencies
const userRoutes = require('./routes/user.routes');
const db = require('./utils/db.utils');
// App setup
const app = express();
const port = parseInt(process.env.APP_PORT, 10) || 3000;
// Implementing CORS
app.use(cors());
// Parse JSON bodies
app.use(express.json());
// Parse URL-encoded bodies
app.use(express.urlencoded({
extended: true,
}));
// App Routes
app.get('/', (req, res) => {
res.send('Welcome to Virtual Classroom. You can access to our documentation by clicking <a target="#" href="https://documenter.getpostman.com/view/10110440/UV5deEZQ"> here</a>.');
});
app.use('/', userRoutes);
app.use('*', (req, res) => {
res.status(404).send('404! Page Not Found. Please check the url again.');
});
/**
* To make sure, app start only if database is found
*/
db.safeConnect().then(
() => app.listen(port, () => console.log(`Webservice listening on port: ${port}`)),
);