Forum Discussion

xenexorowdy's avatar
xenexorowdy
Regular Visitor
3 years ago

nodejs unable to display swagger page in nodejs

i wrote a simple code to test

```

const express = require('express')
const app = express()
const chalk = require('chalk');
const morgan = require("morgan");
const cors = require('cors');
const swaggerUI = require("swagger-ui-express");
const swaggerJsDoc = require("swagger-jsdoc");

require('dotenv').config();

require('./startup/routes')(app);


const options = {
  definition: {
    openapi"3.0.0",
    info: {
      title"Testing API",
      version"1.0.0",
      description"A simple Express Library API",
    },
    servers: [
      {
        url"http://localhost:3000",
      },
    ],
  },
  apis: ["server.js"],
};

app.get("/hello",(req,res)=>
{
  res.send("hello");
})
const port = process.env.APP_PORT;
// const swaggerDocs = swaggerJsDoc(swaggeroption);
// app.use('/api-doc',swaggerUi.serve,swaggerUi.setup(swaggerDocs));
const specs = swaggerJsDoc(options);
app.use("/api-docs", swaggerUI.serve, swaggerUI.setup(specs));
app.use(morgan());
app.use(cors());
app.listen(port,() => {
  console.log(chalk.bold.green(`Listening on port ${port} . . .`));
});
```
but unable to display /api-docs please help
No RepliesBe the first to reply