JavaScript Error [ERR_STREAM_WRITE_AFTER_END]: write after end [npm-request with socket.io] error err_stream_write_after_end write after end,error err_stream_write_after_end write after end

On my server side I have socket server listening and in my own laptop I have socket.io-client service and whenever I turn on both they are connecting.

And when other people request to my server, server sends that request via socket to my laptop and my laptop gets data from localhost using npm-request and gives back the returned data to the server then server show that information to the client.

And here is the error on my server side:

/*

throw er; // Unhandled 'error' event
      ^

**Error [ERR_STREAM_WRITE_AFTER_END]: write after end**
    at write_ (_http_outgoing.js:572:17)
    at ServerResponse.write (_http_outgoing.js:567:10)
    at Socket.<anonymous> (/public_html/api/index.js:37:9)
    at Socket.emit (events.js:187:15)
    at /public_html/api/node_modules/socket.io/lib/socket.js:528:12
    at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
    at writeAfterEndNT (_http_outgoing.js:634:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)

    */

server side code:

var http = require('http');
var fs = require('fs');
var socket_g=null, numOfUsers=0;
var url = require('url'),qs = require('querystring');

var server = http.createServer(function(req, res) {
    if(numOfUsers!=0){
          var urlParts = url.parse(req.url, true),
         urlParams = urlParts.query, 
         urlPathname = urlParts.pathname,
         body = '',
         reqInfo = {};

          req.on('data', function (data) {
            body += data; 
          });

          req.on('end', function () {
            reqInfo.urlPathname = urlPathname; 
            reqInfo.urlParams = urlParams; 
            reqInfo.body = qs.parse(body); 
            reqInfo.urlParts = urlParts;
            console.log(reqInfo.urlPathname)
              socket_g.emit('event', { "path": reqInfo.urlPathname});
          });

        socket_g.on('data',function(data){
              console.log(data.c)
              if(data.c=='application/x-httpd-php' || data.c=='/'){
                    res.writeHead(200, { 'Content-Type': 'text/html' });
                    res.write(data.data);
                    res.end();
              }else{
                    res.writeHead(200, { 'Content-Type': data.c });
                    res.write(data.data);
                    res.end();
              }         
        });
    }else{
        res.writeHead(200, { 'Content-Type': 'text/html' });
            res.end("<h2>There is no client connected!</h2>");
    }
});

var io = require('socket.io').listen(server);
io.sockets.setMaxListeners(0);

io.sockets.on('connection', function (socket) {
    /*console msg*/
    console.log('user connected!');
    /*console msg*/
    socket.setMaxListeners(0);
    numOfUsers++;
    socket_g=socket;
    socket.on('disconnect', function(){
        numOfUsers++;
        /*console msg*/
        console.log('user disconnected');
        /*console msg*/
    });
});


server.listen(3333);

And belove my client side code, which is working on my laptop

var socket = require('socket.io-client')('http://*.*.*.*:3333/');
var http=require("http");
var r = require('request');
var mime = require('mime');
var path = require('path');

socket.on('connect', function(){
	console.log("connected");
});

socket.on('event', function(data){
	console.log(mime.getType(path.extname(data.path).substr(1)));
	var contentType=mime.getType(path.extname(data.path).substr(1));

  r.get({url: "http://localhost/check"+data.path},
		function(error, response, body){
		   //console.log(body);
		   if(contentType){
		   	socket.emit('data', { "data": body,'c':contentType });
		   }
	});

});

socket.on('disconnect', function(){
	console.log("disconnected")
});
Answer:1

I want to re-render my child component without re-rendering the parent component when the parent's state changes. In this example, componentWillReceiveProps is never called. Thank You! Parent ...

I want to re-render my child component without re-rendering the parent component when the parent's state changes. In this example, componentWillReceiveProps is never called. Thank You! Parent ...

  1. react render only child component
  2. react render only child
  3. react re render only child
  4. react render only one child
  5. react render only first child

For a page ("Bill4Time"), the Dashboard shows a table for displaying time entries and entering a new time entry but several control elements do not have ID's associated with them. Interestingly ...

For a page ("Bill4Time"), the Dashboard shows a table for displaying time entries and entering a new time entry but several control elements do not have ID's associated with them. Interestingly ...

We'd like to have two outputs from Webpack - our entire app with all of its dependencies, and a single different page with only one dependency (that isn't shared by the main app). It seems the way ...

We'd like to have two outputs from Webpack - our entire app with all of its dependencies, and a single different page with only one dependency (that isn't shared by the main app). It seems the way ...

  1. multiple entries webpack
  2. multiple entry webpack 4
  3. multi entry webpack
  4. multiple webpack entry points
  5. multiple entry files webpack
  6. multiple entry output webpack
  7. multiple entry points webpack 4
  8. multiple entry points webpack-dev-server
  9. multiple entry points webpack config
  10. webpack multiple entries one output
  11. webpack multiple entries not working

I have a search box which should work with pressing the button and also pressing the Enter key. They both have the same code. The button works perfectly but when it comes to the Enter key, most of the ...

I have a search box which should work with pressing the button and also pressing the Enter key. They both have the same code. The button works perfectly but when it comes to the Enter key, most of the ...