michal2195
michal2195

Reputation: 21

Node.js can't find socket.io - getting 404

there is a ton of threads on this already and I went through some of them, but for some reason I can't get my app to work properly. I'm using node with the following dependencies is package.json:

{
"name": "",
"version": "0.0.1",
"description": "test app",
"dependencies": {
    "socket.io": "~0.9.6",
    "mime": "~1.2.7",
    "express": "3.x"
}
}

I installed it with npm no problem. In my server.js I have:

var dp = require('./custom_modules/dataProcessing');
var express = require('express');
var http = require('http');

var app = express();

var server = http.createServer(app).listen(3000, function(){
  console.log('Express server listening on port 3000');
});

dp.listenToVisitorActivities(server);
// serve static content
app.use(express.static(__dirname + '/public'));

Now, as for the dp, it's my custom module in the directory custom_modules/dataProcessing.js Inside (beside all other logic) I have something like:

var socket = require('socket.io');
var fs = require('fs');

var listenToVisitorActivities = function(server) {
var io = socket.listen(server);
//...
}

exports.listenToVisitorActivities = listenToVisitorActivities;

Finally I have some HTML that includes the following scripts in the head section:

src="/socket.io/socket.io.js"

src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"

src="/javascript/webtracker.js" type="text/javascript"

The included webtracker.js has the following line:

 var socket = io.connect();

The jquery and webtracker files are loaded fine, so are the static html pages. I get 404 for socket.io. Tried a lot of stuff, including:

http://stackoverflow.com/questions/19614512/socket-io-socket-io-js-404-not-found
http://stackoverflow.com/questions/16981396/get-http-localhost3000-socket-io-socket-io-js- 
404-not-found

etc. but still no go. Help please.

Upvotes: 2

Views: 346

Answers (1)

sirrele
sirrele

Reputation: 181

Can you try something like the following? This will ensure that you get your socket.io module.

'use strict';
module.exports = function(Activities) {
var socket = require('socket.io');
var fs = require('fs');

Activities.listenToVisitorActivities = function(server) {
var io = socket.listen(server);
//...

};

Upvotes: 1

Related Questions