How To Implement Node JS In Swagger

In this article, we will learn about how to implement swagger in Node JS using the library

Step 1: In your project structure  first create a swagger folder

 

Step 2: The next step is required an API JSON file, this file we will export from the postman,

open your Postman you can see your API folder right site three dot click on it then after open menu and click on Export option

Now you got API JSON file

Step 3: This API JSON file we have to convert into a swagger file
first, click on this URL https://www.apimatic.io/transformer/

create your account and log in and you can see the below pic dashboard

click on the Transform API option, and you can see one popup model select your postman API JSON file and select the export format mentioned in below pic then click on the convert button

 

Step 4: Finally  we got a file, this file copy into our swagger folder

Step 5: Install the swagger npm package

npm i swagger-ui-express

Step 6: Write the below code on your index/app/main file

const swaggerJson = require('./swagger/swagger.json')
const swaggerUi = require('swagger-ui-express')
app.use('/api-docs',swaggerUi.serve,swaggerUi.setup(swaggerJson))

Step 7: Run your project, then open your browser and run this URL localhost:7600/api-docs this URL in write your server name and PORT number

If you have any query about this article ask me

You can check my other node js article

Node JS FS module: https://www.thecodehubs.com/node-js-url-module

Express validator:  https://www.thecodehubs.com/express-validator-in-node-js

 

 

 

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories