-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (33 loc) · 1.08 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
import express from 'express'
import bodyParser from 'body-parser'
import dbConfig from './config/database.config.js'
import mongoose from 'mongoose'
import routes from './app/routes/note.routes.js'
import swaggerUI from 'swagger-ui-express'
//create express app
const app = express();
var swaggerDocument = require('./swagger.json');
// parse request of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({extended:true}));
// parse requests of content-type - application/json
app.use(bodyParser.json());
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument));
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
}).then(()=>{
console.log("Successfully conneced to the database");
}).catch(err=>{
console.log('Could not connect to database. Exiting now...', err);
process.exit();
});
// define a simple route
app.get('/',(req,res)=>{
res.json({"message":"My Message"});
});
// listen for requests
routes(app);
app.listen(3000, ()=>{
console.log("Server is listening on port 3000");
});