-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (37 loc) · 1.15 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
40
41
42
43
44
45
46
const express = require("express");
const mongoose = require("mongoose");
const app = express();
const orders_routes = require("./routes/orders")
const transactions_routes = require("./routes/transactions")
require('dotenv').config()
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const swaggerDefinition = {
openapi: '3.0.0',
info: {
title: 'Express API for retrieving data from mongodb',
version: '1.0.0',
},
servers: [
{
url: 'http://localhost:3000',
description: 'Development server',
},
],
};
const options = {
swaggerDefinition,
// Paths to files containing OpenAPI definitions
apis: ['./routes/*.js'],
};
const swaggerSpec = swaggerJSDoc(options);
app.listen(process.env.PORT || 3000,()=>{
console.log(`Server running on port ${process.env.PORT}`)
})
mongoose.connect(process.env.MONGO_URI)
.then((result) => console.log('Database running'))
.catch((err) => console.log(Error))
app.use(express.json())
app.use('/api/orders', orders_routes)
app.use('/api/transactions', transactions_routes)
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));