http res.on('end') not working

Posted on
  • Hello,
    I have a pico with an ESP8226 working and trying to move some code that I currently have from a node.js project but it seems that res.on('end') does not work in espruino.
    In order to fix it, I have to change the event from 'end' to 'close'.

    I also tried changing my nodejs app to use 'close' but It does not work there, I know it's an easy change but I was tying to have the code compatible with node.js and espruino.

    Is there a way to add the event 'end' in the http response in espruino?

    Code not working in espruino pico

    	var contents = "";
            require('http').get("­uk/hello.txt", function(res) {
                res.on('data', function(data) {
                    contents += data;
                res.on('end', function() {


  • Thanks - annoyingly end doesn't even have its own heading as an event in the node http reference, I guess since it's on the underlying stream.

    It's odd that close doesn't work in node though. the reference sort of implies it's like end and should work - but perhaps the underlying socket is kept open and so close doesn't get called until a while later.

    I'll add an end event as well though - it should be in the next release, but I added an issue for it so you can keep track of it here

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

http res.on('end') not working

Posted by Avatar for user47006 @user47006