# Connecting node.js to space app.js

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconnecting-node-js-to-space-app-js%2F146563%3E%5C
**Category:** Beginners\
**Created:** [March 20, 2025, 3:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconnecting-node-js-to-space-app-js%2F146563 "2025-03-20T03:14:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khushinpat](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/khushinpat/32/43664_2.png) [@Khushinpat](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKhushinpat)%5C
**Post date:** [March 20, 2025, 3:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconnecting-node-js-to-space-app-js%2F146563%2F1 "2025-03-20T03:14:20Z")

</div>

## Python Code (App.py on Spaces)

```python
import gradio as gr
from PIL import Image

def segment_image():
    # Dummy segmentation (convert to grayscale)
    segmented = img.convert("L")
    return segmented
    
demo = gr.Interface(
    fn=segment_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil"),
)

demo.launch()

```

## JavaScript Code(being run locally on my machine)

I have this code in my JS file that I’m trying to send to my Spaces app, but it’s giving an error I can’t figure out.

```javascript
import { Client } from "@gradio/client";
import fs from 'fs';

const app = await Client.connect("user4635/trial-gradio-blank");

const imageBuffer = fs.readFileSync('./Cristiano_Ronaldo_WC2022_-_02.jpg'); // Replace with your path
const base64Image = `data:image/jpeg;base64,${imageBuffer.toString('base64')}`;

// Send to Gradio
const result = await app.predict("/predict", [
  base64Image // Pass base64 string
]);

const output = result.data[0];

// Save the output image
fs.writeFileSync('./output_image.png', Buffer.from(output.data));

```

## The error on my node console

```auto
node:internal/process/esm_loader:40
      internalBinding('errors').triggerUncaughtException(
                                ^
{
  type: 'status',
  endpoint: '/predict',
  fn_index: 0,
  time: 2025-03-20T02:56:19.193Z,
  original_msg: undefined,
  queue: true,
  title: undefined,
  message: null,
  visible: undefined,
  duration: undefined,
  stage: 'error',
  code: undefined,
  success: false
}

```

Does anyone know why this could be?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 20, 2025, 7:07am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fconnecting-node-js-to-space-app-js%2F146563%2F2 "2025-03-20T07:07:01Z")

</div>

For example, this sometimes happens when the Gradio client and Gradio GUI versions don’t match, but I don’t know how to downgrade the module version using JavaScript…

> **[gradio-app/gradio](https://github.com/gradio-app/gradio/issues)**
>
> Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work! - gradio-app/gradio

> **[Getting Started With The Js Client](https://www.gradio.app/guides/getting-started-with-the-js-client)**
>
> A Step-by-Step Gradio Tutorial

### Same error but unrelated issue…

> <https://github.com/lllyasviel/Fooocus/issues/3686>
>
> \### Checklist
> 
> \- \[X\] The issue has not been resolved by following the \[troublesh…ooting guide\](https://github.com/lllyasviel/Fooocus/blob/main/troubleshoot.md)
> \- \[X\] The issue exists on a clean installation of Fooocus
> \- \[X\] The issue exists in the current version of Fooocus
> \- \[X\] The issue has not been reported before recently
> \- \[\] The issue has been reported before but has not been fixed yet
> 
> \### What happened?
> 
> Using gradio api receive error 
> node:internal/process/esm\_loader:40
> internalBinding('errors').triggerUncaughtException(
> ^
> {
> type: 'status',
> stage: 'error',
> endpoint: '/predict',
> fn\_index: 13,
> message: null,
> queue: false,
> time: 2024-10-16T18:26:15.489Z
> }
> 
> \### Steps to reproduce the problem
> 
> run code shown
> 
> import { client } from "@gradio/client";
> 
> const response\_0 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test\_files/bus.png");
> const exampleImage = await response\_0.blob();
> 						
> const app = await client("https://xxxxxxx.com/", {auth:\['user','password'});
> const result = await app.predict(10, \[
> exampleImage, // blob in 'Image' Image component
> \]);
> 
> console.log(result.data);
> 
> 
> \### What should have happened?
> 
> Not received an error.
> 
> \### What browsers do you use to access Fooocus?
> 
> Google Chrome
> 
> \### Where are you running Fooocus?
> 
> Locally
> 
> \### What operating system are you using?
> 
> WIndows 11
> 
> \### Console logs
> 
> \`\`\`Shell
> C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\>.\\python\_embeded\\python.exe -s Fooocus\\entry\_with\_update.py --port 7866 --listen 0.0.0.0
> Already up-to-date
> Update succeeded.
> \[System ARGV\] \['Fooocus\\\\entry\_with\_update.py', '--port', '7866', '--listen', '0.0.0.0'\]
> Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) \[MSC v.1934 64 bit (AMD64)\]
> Fooocus version: 2.5.5
> \[Cleanup\] Attempting to delete content of temp dir C:\\Users\\Scott\\AppData\\Local\\Temp\\fooocus
> \[Cleanup\] Cleanup successful
> Total VRAM 12282 MB, total RAM 65277 MB
> Set vram state to: NORMAL\_VRAM
> Always offload VRAM
> Device: cuda:0 NVIDIA GeForce RTX 4070 Ti : native
> VAE dtype: torch.bfloat16
> Using pytorch cross attention
> Refiner unloaded.
> Running on local URL: http://0.0.0.0:7866
> model\_type EPS
> UNet ADM Dimension 2816
> IMPORTANT: You are using gradio version 3.41.2, however version 5.0.1 is available, please upgrade.
> \--------
> Using pytorch attention in VAE
> Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
> Using pytorch attention in VAE
> extra {'cond\_stage\_model.clip\_l.text\_projection', 'cond\_stage\_model.clip\_l.logit\_scale'}
> left over keys: dict\_keys(\['cond\_stage\_model.clip\_l.transformer.text\_model.embeddings.position\_ids'\])
> Base model loaded: C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\Fooocus\\models\\checkpoints\\juggernautXL\_v8Rundiffusion.safetensors
> VAE loaded: None
> Request to load LoRAs \[('sd\_xl\_offset\_example-lora\_1.0.safetensors', 0.1)\] for model \[C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\Fooocus\\models\\checkpoints\\juggernautXL\_v8Rundiffusion.safetensors\].
> Loaded LoRA \[C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\Fooocus\\models\\loras\\sd\_xl\_offset\_example-lora\_1.0.safetensors\] for UNet \[C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\Fooocus\\models\\checkpoints\\juggernautXL\_v8Rundiffusion.safetensors\] with 788 keys at weight 0.1.
> Fooocus V2 Expansion: Vocab with 642 words.
> Fooocus Expansion engine loaded for cuda:0, use\_fp16 = True.
> Requested to load SDXLClipModel
> Requested to load GPT2LMHeadModel
> Loading 2 new models
> \[Fooocus Model Management\] Moving model(s) has taken 0.30 seconds
> Started worker with PID 55052
> App started successful. Use the app with http://localhost:7866/ or 0.0.0.0:7866
> 
> To create a public link, set \`share=True\` in \`launch()\`.
> Traceback (most recent call last):
> File "C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\python\_embeded\\lib\\site-packages\\gradio\\routes.py", line 488, in run\_predict
> output = await app.get\_blocks().process\_api(
> File "C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\python\_embeded\\lib\\site-packages\\gradio\\blocks.py", line 1429, in process\_api
> inputs = self.preprocess\_data(fn\_index, inputs, state)
> File "C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\python\_embeded\\lib\\site-packages\\gradio\\blocks.py", line 1239, in preprocess\_data
> processed\_input.append(block.preprocess(inputs\[i\]))
> File "C:\\Users\\Scott\\Downloads\\Fooocus\_win64\_2-5-0\\Fooocus\\modules\\gradio\_hijack.py", line 277, in preprocess
> assert isinstance(x, str)
> AssertionError
> \`\`\`
> 
> 
> \### Additional information
> 
> \_No response\_
