-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (24 loc) · 936 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
34
35
36
const express = require("express");
const cors = require("cors");
const PORT = process.env.PORT || 3000;
const mongoose = require("mongoose");
const routes = require('./routes/endpoints');
const app = express();
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//Establishing connection with database
const DB_URL = 'mongodb+srv://user799:[email protected]/Shop?retryWrites=true&w=majority';
mongoose.Promise = global.Promise;
mongoose.connect(DB_URL, { useNewUrlParser: true })
.then(
() => { console.log('Database is connected') },
err => { console.log('Can not connect to the database' + err) }
);
let db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error"));
//retrieving all data
app.use("/", routes.common);
const server = app.listen(PORT, () => {
console.log("Server started at http://localhost:" + PORT);
});