error init 'socket.io' for node
See original GitHub issue
- 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:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
upgarde node to v12.19.0 OK
@cellcrowd good catch, thanks! the version was updated: https://socket.io/docs/v3/server-installation