How to use Swagger in NodeJs from scratch

Posted By : Rajat khurana | 29-Dec-2017
Swagger in node js 
 
Hi guys, here you will learn how to use swagger in node js. Node js, open source, Javascript run time environmentt for running any Javascript code. Its demand is increasing day by day. Now come to API point of view. Whenever we create an API then we mention its path in any sheet just to remember which API is this and what its request and response parameters. TO get rid of all this manual work, a module is introduced in node called swagger-node-express. With the help of this module we can create nice api-docs based on our requirement and make our project with nice API docs in structure way.
 
One more advantage of this module is that it also help to generate structure of project and also based on our requirement we will modify it.Let's start with it.
 
1) First of all install swagger module in node js using npm 
npm install -g swagger
 
2) Create a project using swagger
swagger project create project name
 
then it ask you for framework, select the framework which you want to use.In this file you will see attribute "x-swagger-router-controller" and its value represent the name of controller you are using and attribute "operationid" value specify function use in that controller. Each and every controller file is placed in api/controller directory. You can modify its structure by adding service directory or anything else you want to do. 
 
3) Open your API doc file( yaml) and edit in browser having GUI interface of API also on another side.
swagger project edit
 
4) Finally you can run your project by using this command.
 swagger project start

About Author

Author Image
Rajat khurana

Rajat is a bright Javascript Developer, he has good knowledge of HTML, WordPress, NodeJs, Core Java, Javascript, Jquery. Apart from this he loves to play Badminton and PC Gaming.

Request for Proposal

Name is required

Comment is required

Sending message..