-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (35 loc) · 1.24 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
// FileName: index.js
// Import express
let express = require('express')
let apiRoutes = require("./api-routes")
let bodyParser = require("body-parser");
let mongoose = require('mongoose');
var cors = require('cors');
const dotenv = require("dotenv");
dotenv.config();
// Initialize the app
let app = express();
app.use(cors());
// Configure bodyparser to handle post requests
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
// Setup server port
var port = process.env.PORT || 5000;
// Send message for default URL
//app.get('/', (req, res) => res.send('Hello World with Express'));
app.use('/api',apiRoutes);
// Launch app to listen to specified port
mongoose.Promise = global.Promise; // mongoose promises deprecated, use node - mongoosejs.com/docs/promises
//mongoose.connect('mongodb://localhost/mymoviex', { useNewUrlParser: true,useCreateIndex: true});
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true,useCreateIndex: true});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("Db connected successfully")
});
app.listen(port, function () {
console.log("Running RestHub on port " + port);
});
module.exports = app;