Skip to content

Commit 4eb67b2

Browse files
committed
Added Swagger documentation setup to the Express.js app
1 parent a4a5731 commit 4eb67b2

File tree

4 files changed

+643
-1
lines changed

4 files changed

+643
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
require('dotenv').config();
33

44
const express = require('express');
5+
const swaggerJsdoc = require('swagger-jsdoc');
6+
const swaggerUi = require('swagger-ui-express');
7+
const swaggerSpec = require('./swaggerDocs');
8+
59
const app = express();
610

711
const session = require('express-session');
@@ -38,6 +42,9 @@ require('./config/db')();
3842
app.use(express.json());
3943
app.use(express.urlencoded({ extended: true }));
4044

45+
// Swagger UI setup
46+
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
47+
4148
app.use('/notes', notesRoutes);
4249
app.use('/', authRoutes);
4350

@@ -54,4 +61,4 @@ const PORT = process.env.PORT || 3000
5461

5562
app.listen(PORT, ()=>{
5663
console.log(`App is listening on port ${PORT}`)
57-
});
64+
});

0 commit comments

Comments
 (0)