-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (48 loc) · 1.48 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
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const url = 'mongodb://localhost:27017/expenseManager';
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
const ejs = require('ejs');
const path = require('path')
const userRoutes = require('./routers/users');
const accountRoutes = require('./routers/account');
const trasactionRoutes = require('./routers/transaction');
mongoose.connect(url, {
useNewUrlParser : true
}).then(() => {
console.log('Database connected successfully...');
}).catch(err => {
console.log('err in database connection : ', err);
});
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '/assets')));
app.use(cookieParser())
app.use('/user', userRoutes);
app.use('/account', accountRoutes);
app.use('/transaction', trasactionRoutes);
app.get("/web", async function home (req, res) {
try {
res.render("pages/web");
} catch (err) {
return res.status(400).json({
msg : 'Something went wrong!'
});
}
})
app.get("/home", async function home (req, res) {
try {
res.render("pages/home");
} catch (err) {
return res.status(400).json({
msg : 'Something went wrong!'
});
}
})
app.listen(port, () => {
console.log('Listening to the port :', port);
});