I am trying to build NodeJS/Express/SocketIO application.
Imports:
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server)...
Configuration:
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
In my Jade template:
script(type='text/javascript', href='/socket.io/socket.io.js')
But '/socket.io/socket.io.js' is not available when I am trying to reach it on
http://localhost:3000/socket.io/socket.io.js
As it says:
Cannot GET /socket.io/socket.io.js
How do I serve socket.io.js from the installed module?
Thanks
You need to copy the client code from an inner Socket.io directory to your public directory. In Socket 0.9, the path to the distributable files is node_modules/socket.io/node_modules/socket.io-client/dist
.
You do not have to copy any files, socket.io will take care of the delivery of the file.
var express = require('express'),
app = new express(),
server = require('http').createServer(app),
io = require('socket.io').listen(server)
In Express 3/4 you can initialize socket.io like so:
var io = require("socket.io")(app.listen(80));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With