-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (36 loc) · 1.1 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
const express = require ('express');
const mongoose = require ("mongoose");
const bodyParser = require ("body-parser");
const cors = require ("cors");
const passport = require ("passport");
//connecting to mongo db
const config = require ("./config/database");
mongoose.connect(config.database);
mongoose.connection.on('connected',() => {
console.log("database connected "+ config.database);
});
mongoose.connection.on('error',(err) => {
console.log("Error while connecting to db: "+err);
});
//initialize express obj
const app = new express();
const port = 2000;
//cors middleware
app.use(cors());
//body parser midleware
app.use(bodyParser.json());
//authentication (Passport jwt middleware)
app.use(passport.initialize());
app.use(passport.session());
require('./config/passport')(passport);
// user module
const users = require ('./controllers/users.js');
app.use('/users',users);
//index route
app.get('/',(req,res)=>{
res.status(200).send("HI this is home passsssssaaaawwwssssddssgesss");
})
//start server
app.listen(port,function(){
console.log("Server is listening on port ::" + port);
})