npm install express swagger-jsdoc swagger-ui-express
const express = require('express');
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUI = require('swagger-ui-express');
const app = express();
const port = 3000;
// Swagger configuration
const swaggerOptions = {
definition: {
openapi: '3.0.0',
info: {
title: 'Your API Title',
version: '1.0.0',
description: 'API Documentation using Swagger',
},
},
apis: ['./routes/*.js'], // Path to the API routes
};
const swaggerSpec = swaggerJSDoc(swaggerOptions);
// Serve Swagger UI at /api-docs
app.use('/api-docs', swaggerUI.serve, swaggerUI.setup(swaggerSpec));
// Define your API routes here (replace with your actual routes)
app.get('/', (req, res) => {
res.send('Hello, Swagger!');
});
// Start the server
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
No comments:
Post a Comment