1.0.1 • Published 3 years ago
rest_api-basicone-api v1.0.1
Simple API In NodeeJs
In this example application, we use Swagger JSDoc and Swagger UI Express to automatically generate OpenAPI documentation. We create a simple NodeJS API server to demonstrate the power of autogenerated documentation.
Required Dependancy
S.No | List of Commands | Description |
---|---|---|
1 | npm init | This command initializes a package.json file with all the settings that the creator wishes to include. |
2 | package.json | The user will be prompted to enter configuration details one after the other. Apart from the normal settings, user can also open the package.json file and add/delete configuration settings such as additional scripts or dependencies etc...- |
3 | npm install | Once the package.json file is configured, user can simply run this command to install all the dependencies, devDependencies and everything mentioned in the package.json file in one go. |
4 | npm i -g jest | This command enables the user to install jest framework globally for unit testing 7 code coverage. |
5 | npm i -g jsdoc | This command enables the user to install jsdoc tool globally for documentating his/her code. |
6 | npm i -g eslint | This command enables the user to install the eslint tool globally for linting purposes. *Refer to NOTE. |
7 | npm eslint --init | This command enables the user to setup the eslint according to the developer styles and rules |
8 | npm i -g axios | Apart from jest, we've added the support of axios for testing our api. This command enables us to install axios globally. |
9 | npm eslint file.js | According to package.json configuration, this command will fix all fixable possible errors in all .js files in the src & tests directory. |
10 | npm run doc | According to package.json configuration, this command will produce the documentation reports for all .js files. |
11 | npm test | This command will run the tests for desired project along with code coverage. |
12 | npm publish | This command will simply publish the package file to the npm global package registry. If already present, it will follow semantic versioning. |
Running the Server
With NodeJS installed, you can started the server by running,
node src/app.js
OR
npm run start
Accessing the Docs
With your local server running, the generated docs are available here: http://localhost:3000/api-docs
Development
This simple server can be easily extended. After cloning this repository you can start developing locally.
Locally (without Docker)
- Install Nodemon, Nodemon will watch for file changes and restart the NodeJS process. This allows for faster development and testing.
npm install -g nodemon
- With Nodemon installed, start the server using Nodemon
nodemon src/app.js
OR
npm run start
Author : Yograj thakur
Date : 09/11/2020
1.0.1
3 years ago