question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error init 'socket.io' for node

See original GitHub issue
  1. server.js
const content = require('fs').readFileSync(__dirname + '/index.html', 'utf8');

const httpServer = require('http').createServer((req, res) => {
  // serve the index.html file
  res.setHeader('Content-Type', 'text/html');
  res.setHeader('Content-Length', Buffer.byteLength(content));
  res.end(content);
});

const io = require('socket.io')(httpServer);

io.on('connect', socket => {
  console.log('connect');
});

httpServer.listen(3000, () => {
  console.log('go to http://localhost:3000');
});

============================== 2) index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Minimal working example</title>
</head>
<body>
    <ul id="events"></ul>

    <script src="/socket.io/socket.io.js"></script>
    <script>
        const $events = document.getElementById('events');

        const newItem = (content) => {
          const item = document.createElement('li');
          item.innerText = content;
          return item;
        };

        const socket = io();

        socket.on('connect', () => {
          $events.appendChild(newItem('connect'));
        });
    </script>
</body>
</html>

=========================== error:

c:\111\node_modules\socket.io\dist\index.js:248 stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError) ; ^

TypeError: stream_1.pipeline is not a function at Function.sendFile (c:\111\node_modules\socket.io\dist\index.js:248:26) at Server.serve (c:\111\node_modules\socket.io\dist\index.js:224:16) at Server.srv.on (c:\111\node_modules\socket.io\dist\index.js:185:22) at emitTwo (events.js:126:13) at Server.emit (events.js:214:7) at parserOnIncoming (_http_server.js:602:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:116:23)

(win7 x64)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nono002commented, Nov 9, 2020

upgarde node to v12.19.0 OK

0reactions
darrachequesnecommented, Nov 10, 2020

@cellcrowd good catch, thanks! the version was updated: https://socket.io/docs/v3/server-installation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Initialization | Socket.IO
Once you have installed the Socket.IO server library, you can now init the server. The complete list of options can be found below....
Read more >
Socket.io initialization resulting in a 404 network error
I am using nodejs and express to create a basic chat app and I'm getting a network 404 error message when trying to...
Read more >
socket.io - npm
node.js realtime framework server. Latest version: 4.5.4, last published: a month ago. Start using socket.io in your project by running `npm ...
Read more >
Create a Secure Chat Application with Socket.IO and React
You should not receive any error messages but you also will not see much at this point because the server is not connecting...
Read more >
Socket.IO, React and Node.js: Going Real-Time
If you worked before with Node.js, the code above should be no mystery to you. You can notice the call to socketIo() to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found