-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (31 loc) · 1.13 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
const express = require('express');
const path = require ('path');
var bodyParser = require('body-parser')
const mongoose = require('mongoose');
//setup url and connecting mongodb..
const mongoDB = 'mongodb://localhost:27017/nodeproject';
//mongoose.connect(mongoDB);
mongoose.connect(mongoDB, (err, client) =>{
if (err) throw err
mongoose.Promise = global.Promise; // Get Mongoose to use the global promise library : so we can use mongoose globably
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
})
//created the app varible so we can use express framework throughtout the project
const app = express();
//port we want to run
const port = 9999;
//configure the app...
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.urlencoded({
extended: true
}));
// import routes
const index = require('./routes/index')
const api = require('./routes/api')
// set routes
app.use('/', index)
app.use('/api', api)
app.listen(port, () => console.log(`Server Started on port ${port}!`))