node.js tutorial: API calculator using Swagger

So let’s start the tutorial!!

1st step: Open the command line and use the following commands to create the project.

mkdir calculatorSwagger
cd calculatorSwagger
npm init

2nd step: Install the necessary dependencies (express and swagger-ui)

npm install express
npm install swagger-ui-express --save

3rd step: Create index.js and swagger.json files

touch index.js
touch swagger.json

4th step: Place the following code in the index.js file

5th step: Place the following code in the swagger.json file where we are going to create the elementary arithmetic operations (sum, subtraction, multiplication and division)

Last step: Run the project

node index.js

And test the operations

Sum operation
Subtraction operation
Multiplication operation
Division operation

--

--

--

Finalist student in Computer Engineering

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Understand Code Splitting in Next.js by Solving a Common Error

Passing anonymous function as a parameter in javascript function

Creating A Player Name Using JavaScript

Which is best JavaScript Development framework :- AngularJS vs EmberJS vs BackboneJS

Learning CSS Animations with a touch of Javascript

Declarative direct manipulation in react with AQUEDUX

What is GraphQL and how to use with React.js (Part 2)?

Why I built the simplest async universal React Redux boilerplate I could

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Afonso Antunes

Afonso Antunes

Finalist student in Computer Engineering

More from Medium

JavaScript, NoSQL and MongoDB

Introduction Node.js

How To Test a NodeJS Module using Mocha and Assert

NestJS and MongoDB (using Mongoose)

NestJS and MongoDB logos