> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter2-nodejs/29node-+-swagger.md).

# 2.9.Node Swagger mock server

* 1.Swagger-ui
  * 1.Introduction
  * 2.Create a Swagger server by using express
    * 1.Create folder for project

      ```
            express -e swagger-server
            cd swagger-server
            npm install
      ```
    * 2.Modify app.js

      ```
            app.listen(3000);
      ```
    * 3.Download **swagger-ui**, copy all files and folders from dist folder to public folder from project folder

      ```
            git clone https://github.com/swagger-api/swagger-ui.git
            cd swagger-ui
      ```

      * 4.Run node server and open browser, you can see the default data (<http://petstore.swagger.io/v2/swagger.json>)

        ```
           cd ..
           cd swagger-server
           node app.js
        ```
      * 5.Edit JSON file and **Download JSON** (uber.json)from [Swagger editor](http://editor.swagger.io/#!/)

      ![](/files/-M4M0NmkXz4Vcq6AlfZ8)

      * 6.Copy JSON file to project folder and modify **index.html**

        ```
        window.onload = function() {
         // Build a system
         const ui = SwaggerUIBundle({
            url: "./uber.json",
            dom_id: '#swagger-ui',
            presets: [
                SwaggerUIBundle.presets.apis,
                // yay ES6 modules ↘
                Array.isArray(SwaggerUIStandalonePreset) ? SwaggerUIStandalonePreset : SwaggerUIStandalonePreset.default            ],
            plugins: [
                    SwaggerUIBundle.plugins.DownloadUrl],
                layout: "StandaloneLayout"
            })
            window.ui = ui
        }
        ```
      * 7.Restart Node.js and open localhost:3000, but it can not show response from server when you try to use API on the current panel.

        ```
           node app.js
        ```

        * swagger-ui just can provide ability to show API document, so you have to build and run a mock server .

![](/files/-M4M0NmnHuib2Fkln8mL)

* 2.mock server
  * 1.Clone from respostory

    ```
          git clone https://github.com/bigstickcarpet/swagger-express-middleware.git
    ```
  * 2.Install dependencies

    ```
          npm install
          cd swagger-express-middleware
    ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/javascript-node-js/chapter2-nodejs/29node-+-swagger.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
