# Loading model files by setting the path as a parameter in the URL

**URL:** <https://discourse.threejs.org/t/loading-model-files-by-setting-the-path-as-a-parameter-in-the-url/65609>\
**Category:** Questions\
**Tags:** node-js, url\
**Created:** [May 16, 2024, 4:38am UTC](https://discourse.threejs.org/t/loading-model-files-by-setting-the-path-as-a-parameter-in-the-url/65609 "2024-05-16T04:38:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JKLEE](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@JKLEE](https://discourse.threejs.org/u/JKLEE)\
**Post date:** [May 16, 2024, 4:38am UTC](https://discourse.threejs.org/t/loading-model-files-by-setting-the-path-as-a-parameter-in-the-url/65609/1 "2024-05-16T04:38:03Z")

</div>

\*\*\* Using THREE.js to create a 3D viewer space and loading gltf models into the viewer space via node.js express.

\*\*\* Currently, when accessing the default address [http://localhost](http://localhost):port/, it displays the HTML,

```
app.get('/', (req, res) => {
      res.sendFile(__dirname + '/mythreeviewer.html');
});

```

\*\*\* The following code sends a request for the gltf file to be loaded at a specific url.

```
async function getModelData() {
  try {
    const response = await fetch('http://localhost:port/getModel');

    if (!response.ok) {
        throw new Error('Network response was not ok');
    }
    const data = await response.json();

    return data;

    } catch (error) {
       throw error;
    }
}

```

\*\*\* Server-side response handling for the request is as follows.

```
app.get('/getModel', (req, res) => {

  const directoryPath = "D:/Temp/modelA.gltf";

 try {
   // Navigate to a specific path and retrieve the model file.
 }
 catch (error){
   console.error('Error handling request:', error);
   return res.status(500).json({ error: 'Error handling request' });
 }
});

```

* * *

What I want to achieve going forward is this.

When a user accesses [http://localhost](http://localhost):port/model/AAA  
(or [http://localhost](http://localhost):port/model/BBB, CCC, DDD …)

The server should display the default HTML and at the same time read the gltf file within the “D:/Temp/model/AAA/” path.  
In other words, the server-side should handle the value passed as a URL parameter to load the model.

However, I also need to provide the HTML. Please advise on how to do this.
