-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 779 Bytes
/
server.js
File metadata and controls
29 lines (24 loc) · 779 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
const SwaggerExpress = require('swagger-express-mw');
const app = require('express')();
const mongoose = require('mongoose');
const apiConfig = require('./api/config/config');
// Export the express app for testing purposes
module.exports = app;
const swaggerConfig = {
swaggerFile: `${__dirname}/api/controllers/swagger/swagger.yaml`,
configDir: `${__dirname}/api/config/swagger`,
appRoot: __dirname,
};
// Establish the connection with the database
mongoose.connect('mongodb://127.0.0.1:27017/node_swagger_api_db', (error) => {
if (error) {
throw Error('Error establishing a connection to the database');
}
});
SwaggerExpress.create(swaggerConfig, (err, swagger) => {
if (err) {
throw err;
}
swagger.register(app);
app.listen(apiConfig.port);
});