Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/milan-960/nodejs-swagger-api
Simple REST API on Nodejs server build using swagger-ui and ejs.
https://github.com/milan-960/nodejs-swagger-api
ejs nodejs reactjs rest-api swagger swagger-ui vercel
Last synced: about 2 months ago
JSON representation
Simple REST API on Nodejs server build using swagger-ui and ejs.
- Host: GitHub
- URL: https://github.com/milan-960/nodejs-swagger-api
- Owner: Milan-960
- License: mit
- Created: 2023-03-08T13:43:26.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T15:57:30.000Z (over 1 year ago)
- Last Synced: 2024-04-11T04:54:30.414Z (9 months ago)
- Topics: ejs, nodejs, reactjs, rest-api, swagger, swagger-ui, vercel
- Language: JavaScript
- Homepage: https://nodejs-swagger-api.vercel.app
- Size: 697 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
## Follow the steps below to create a RESTful server using swager!
## Here is the Tree
```
┣ 📂public
┣ 📂src
┃ ┣ 📂Data
┃ ┃ ┗ 📜data.js
┃ ┣ 📂Routes
┃ ┃ ┗ 📜posts.js
┃ ┣ 📂views
┃ ┃ ┣ 📂pages
┃ ┃ ┃ ┣ 📜index.css
┃ ┃ ┃ ┣ 📜index.ejs
┃ ┃ ┃ ┗ 📜log.jpeg
┃ ┃ ┣ 📂public
┃ ┃ ┃ ┗ 📜index.css
┃ ┃ ┗ 📜.DS_Store
┃ ┣ 📜.DS_Store
┃ ┗ 📜hello.js
┣ 📜.DS_Store
┣ 📜.babelrc
┣ 📜.gitignore
┣ 📜Readme.md
┣ 📜index.js
┣ 📜nodemon.json
┣ 📜now.json
┣ 📜package-lock.json
┣ 📜package.json
┗ 📜vercel.json
```## Firstly let’s create a RESTful web server:
## Navigate the cursor to the file I will create the project in the terminal and I am creating the package.json file with the following command:
```
npm init --y
```## Now let’s add the packages that are necessary to create the server:
```
npm install express cors morgan body-parser dotenv
```## let’s add the babel modules to the project:
```
npm install @babel/core @babel/node @babel/preset-env
```## let’s create the .babelrc file and add the following code:
```
{
“presets”: [“@babel/preset-env”]
}
```## And finally, let’s add the following code to scripts field in the package.json file.
```
"start": "nodemon — exec babel-node src/index.js"
```### If you don’t have nodemon in your PC, I advise installing it globally.
```
sudo npm install -g nodemon
```## Adding Swagger to the project
Firstly, let’s install two modules that are necessary for documentation and user interface (UI):
```
npm install swagger-jsdoc swagger-ui-express
```## And I am importing these two modules in the index.js file:
```
import swaggerUI from “swagger-ui-express”;
import swaggerJsDoc from “swagger-jsdoc”;
```# 🍎 PS: If you have any other ideas about what can be improved please share your thoughts I would really appreciate that!
## Nodejs server built and maintained by [Milan Sachani 💜](https://milansachani.dev)