# Wating for Http request makes node-red unresponsive / freezes

**URL:** <https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191>\
**Category:** Developing Nodes\
**Created:** [19 November 2020 12:16 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191 "2020-11-19T12:16:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivovargasitel](https://avatars.discourse-cdn.com/v4/letter/i/db5fbb/32.png) [@ivovargasitel](https://discourse.nodered.org/u/ivovargasitel)\
**Post date:** [19 November 2020 12:16 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/1 "2020-11-19T12:16:42Z")

</div>

Hi,  
I'm trying to do a node like "http request", i used the source of this node as inspiration,  
but when i do a request that the remote address takes some time to respond or don't respond at all, my node-red gets stuck.  
The "http request" node doesn't do that.

I tried with the library "Got" with the same result.

```auto
node.on('input', (msg, send, done) => {
    request('http://192.168.200.220:1880/test', function(err, res, body) {
        if(err) {
            msg.payload = 'Error';
            msg.statusCode = 404;
            node.send(msg);
            done();
        } else {
            msg.payload = body;
            msg.statusCode = 200;
            node.send(msg);
            done();
        }
    });

  /*(async () => {
        try {
            const response = await got('http://192.168.200.220:1880/test');

            if(response !== undefined) {
                msg.payload = response.body;
                msg.statusCode = 200;
                node.send(msg);
                done();
            } else {
                msg.payload = "Error";
                msg.statusCode = 404;
                node.send(msg);
                done();
            }
                    
       } catch(error) {
           msg.payload = 'Error';
           msg.statusCode = 404;
           node.send(msg);
           done();
       }
   })();*/
});

```

I use a disconnected "http in" node to test a non responsive http request.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/6/265ffe37b2254d4e1156b896072d6b59fc1854b7.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 November 2020 14:32 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/2 "2020-11-20T14:32:02Z")

</div>

I've been using the Axios library to help with my smart heating module [node-drayton-wiser](https://github.com/TotallyInformation/node-drayton-wiser) and that seems to work OK with Node-RED.

I've included `require` in the globals in settings.js on my dev machine and then have some functions that look like this:

```auto
/** Create class instance and try to connect */
const require = global.get('require')

const wiser = require('node-drayton-wiser')()

wiser.setConfig({
    ip: msg.payload.host,
    secret: msg.payload.secret,
})

//wiser.debug()

// Quick Connection Test
wiser.testConnection()
    .then( d => {
        msg.payload = d
        msg.topic = 'Wiser Test Connection'
        node.send(msg)
    })

// Test get of specific controller data section
wiser.get('network')
    .then( res => {
        if ( res.error ) {
            msg.payload = res.error
            msg.topic = 'Wiser Get ERROR'
            node.send(msg)
        } else {
            msg.payload = res
            msg.topic = 'Wiser Get SUCCESS'
            node.send(msg)
        }
    })
    .catch( err => {
        msg.payload = err
        msg.topic = 'Wiser Get ERROR (catch)'
        node.send(msg)
    })

//return msg

```

The functions in my module are mainly Promise-based since that's what Axios uses.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 November 2020 14:36 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/3 "2020-11-20T14:36:22Z")

</div>

Do you really want to do the require every time the function is called ?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 November 2020 14:38 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/4 "2020-11-20T14:38:08Z")

</div>

😃 It is only a convenience for testing Dave. I wouldn't do that on a live system. Ultimately, it will all get written into a custom node of course, this is just a quick and easy way to get started.

It would, of course, be nice if the setup tab allowed you do set a variable that the main tab could consume. Sorry, didn't explain that well. I mean that a `const x = "something` which would mean that you could also create a function at startup that the function node could then use.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 November 2020 14:53 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/5 "2020-11-20T14:53:07Z")

</div>

> [@TotallyInformation](#):
>
> be nice if the setup tab allowed you do set a variable that the main tab could consume

iindeed you can write to context from the setup and then retrieve in the main as now - but yes would be nice if more direct.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 January 2021 14:53 UTC](https://discourse.nodered.org/t/wating-for-http-request-makes-node-red-unresponsive-freezes/36191/6 "2021-01-19T14:53:14Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
