-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (32 loc) · 1022 Bytes
/
server.js
File metadata and controls
42 lines (32 loc) · 1022 Bytes
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
41
42
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
//MONGOOSE CONNECTION
mongoose.connect('mongodb://localhost/contactApi');
mongoose.Promise = global.Promise;
//DATABASE CONNECTING CHECK
const db = mongoose.connection;
db.on('error', err => {
console.log('Database Connection error'+ err);
});
db.once('open', () => console.log('Database Connected'));
//IMPORT ROUTE
const contactRouter = require('./api/route/contactRoute');
const userRouter = require('./api/route/userRoute');
//PORT
const PORT = process.env.PORT || 3030;
//MIDDLEwARE
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use('/api/contacts', contactRouter);
app.use('/api/users', userRouter);
//ROOT ROUTE
app.get('/', (req, res) => {
res.json({
message: 'Everythong is oke!'
});
});
app.listen(PORT, () => {
console.log('Im listening on port '+PORT);
});