-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (32 loc) · 920 Bytes
/
index.js
File metadata and controls
41 lines (32 loc) · 920 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
const express = require('express');
const bodyParser = require('body-parser');
const port = 3000;
//create express app
const app = express();
//middleware
app.use(bodyParser.urlencoded({ extended: true}));
app.use(bodyParser.json());
//Configuring database
const dbConfig = require('./config/database.config');
const mongoose = require('mongoose');
mongoose.promise = global.Promise;
//Connecting to the database
mongoose.connect(dbConfig.url, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then( () => {
console.log('Successfully connected to database');
}).catch((err) => {
console.log('Could not connected to database', err);
process.exit();
});
//rest
app.get('/', (req,res) => {
res.json({
"message": "Welcome to Node with Mongo"
});
});
require('./app/routes/note-route')(app);
app.listen(port, () => {
console.log(`Server is listening on Port ${port}`);
});