Error view:
Uncaught ReferenceError: require is not defined **socket.io.js:11** Swears at the line:
var client = require('socket.io-client'); Connection is:
<script src="/node_modules/socket.io/lib/socket.io.js"></script> Who faced?
Error view:
Uncaught ReferenceError: require is not defined **socket.io.js:11** Swears at the line:
var client = require('socket.io-client'); Connection is:
<script src="/node_modules/socket.io/lib/socket.io.js"></script> Who faced?
This is because require for the node.js code, not the browser.
require is only running on the server. For example :
var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on('my other event', function (data) { console.log(data); }); }); Here’s how to use socket.io in a browser:
<script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect('http://localhost'); socket.on('news', function (data) { console.log(data); socket.emit('my other event', { my: 'data' }); }); </script> Of course, you need to make sure that socket.io is installed, and that the path /socket.io/socket.io.js exists, and that the server is providing it.
npm install socket.io . Already done? - Peter DanilovichSource: https://ru.stackoverflow.com/questions/265245/
All Articles