-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (43 loc) · 1.62 KB
/
index.js
File metadata and controls
55 lines (43 loc) · 1.62 KB
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 path = require('path');
const bodyParser = require('body-parser');
const cors = require('cors');
const mongoose = require('mongoose');
const exphbs = require('express-handlebars');
const session = require('express-session');
const config = require('./config/database');
mongoose.Promise = global.Promise;
// Connect To Database
mongoose.connect(config.database);
// On Connection Successful
mongoose.connection.on('connected',() =>{
console.log('Connected to database ' +config.database);
});
// On Error Connection
mongoose.connection.on('error',(err) =>{
console.log('Error to database connection ' +err);
});
// Models & Routes initialization to index page
const app = express();
// Set Static Public folder (SABAI CHANGE GARNWA BAKI XA HAI SALA TANAB GARXA YESLA SECURITY KO LAGI )
app.use(express.static(path.join(__dirname, 'public')));
app.use("/tether", express.static(__dirname + "/node_modules/tether/dist/"));
app.use("/popper", express.static(__dirname + "/node_modules/popper.js/dist/"));
// Routes initial Initialization
const home_page = require('./routes/home'); // Index-Page
// Port Number to Start
const port = 3300;
app.use(cors());
// Body parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// view engine setup i.e HBS
app.set('views',path.join(__dirname,'views'));
app.engine(".hbs", exphbs({ defaultLayout: "mainlayout", extname: ".hbs"}));
app.set("view engine", ".hbs");
// Index Page Route
app.use('/',home_page);
// Server starting
app.listen(port, () => {
console.log('server started on part '+port);
});