-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (29 loc) · 899 Bytes
/
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
40
const express = require('express');
const mongoose = require('mongoose');
const server = express();
const routes = require('./routes/routes');
const cors = require('cors');
// initializing server
const port = process.env.PORT || 3000;
// mongodb connection string
mongoose.connect("mongodb://127.0.0.1:27017/mean_crud", {
useNewUrlParser: true,
useUnifiedTopology: true
}, function checkDB(error) {
if (error) {
console.log('Not Connected to the database, err: ' + error);
} else {
console.log('Connection Successfully, Now Connected to the DataBase on MongoDB ');
}
});
// server configuration
server.use(cors());
server.use(express.json());
server.use(routes);
server.listen(port, function check(error) {
if (error) {
console.log('Error on server: ' + error);
} else {
console.log('Server running on port ' + port);
}
});