-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
33 lines (29 loc) · 926 Bytes
/
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
/**
* root file for api configuration
*/
const express = require("express");
const bodyParser = require("body-parser");
const routes = require("./app/routes/recipes.routes");
const dbConfig = require("./config/database.config");
const moongoose = require("mongoose");
moongoose.Promise = global.Promise;
moongoose
.connect(dbConfig.url)
.then(() => {
console.log("successfully connected to the database");
})
.catch(() => {
console.log("unable to connect to the database Exiting now..");
process.exit();
});
// create express app
const app = express();
// parse requests of content-type - application/json
app.use(bodyParser.json());
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));
routes(app);
// listen for requests
const server = app.listen(3004, function() {
console.log("app running on", server.address().port);
});