-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (26 loc) · 1.03 KB
/
server.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
const express = require('express');
var app = express();
var port = process.env.PORT || 3000;
const bodyParser = require('body-parser');
// support parsing of application type post data
app.use(bodyParser.json());
//support parsing of application/x-www-form-urlencoded post data
// app.use(bodyParser.urlencoded({
// extended: true
// }));
/**** ROUTE ****/
var routes = require('./api/routes/productRoutes'); //importing route
routes(app); //register the route
/**** mongoose connect to Atlas DB ****/
const mongoose = require('mongoose');
const uri = "mongodb+srv://linoravny:<PASSWORD>@cluster0.ps0o2.azure.mongodb.net/testAppUsersDB?retryWrites=true&w=majority";
let opts = { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true };
mongoose.connect(uri, opts);
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB database connection established successfully");
});
/**** PORT ****/
app.listen(port, () => {
console.log(`Server listening at ${port}`);
});