not found on client

This question has been asked previously but haven't found any solution in prior replies.

Socket.IO gives me two problems:

  1. server side gave this error - ERROR - listen EACESS I read stackoverflow and resolved this with issuing a sudo command to start the server.
  2. now clientside doesnt seem to find the file as per the script line -

I understand file is not found by using the chrome developer tools console which has a 404 error on the file.

I read that this file is created on the fly by server. But I did a 'ls-a' on the root folder. Couldn't find the file.

Any ideas?

For reference here is my server code -

var http = require('http'),
  path = require("path"),
  url = require("url"),
  fs = require("fs"),
  mime = require("mime"),
  io = require("").listen(server);
var homepath = ".";
var server = http.createServer(function (req, res) {
  var uri = url.parse(req.url).pathname;
  var filepath = path.join(homepath, uri);
  path.exists(filepath, function (exists) {
    if (!exists) {
      //404 response
      res.writeHead(404, {
        "Content-Type": "text/plain"
      res.write("404 File not Found \n");
    } else {
      if (fs.statSync(filepath).isDirectory()) {
        filepath += '/index.html';
        filepath = path.normalize(filepath);
      fs.readFile(filepath, "binary", function (err, data) {
        if (err) {
          res.writeHead(500, {
            'Content-Type': 'text/plain'
          res.write('500 File read error \n');
        } else {
          var contentType = mime.lookup(filepath);
          res.writeHead(200, {
            'Content-Type': contentType
          res.write(data, 'binary');
  //sockets part starts here
  io.sockets.on('connection', function (socket) {
    socket.on('test', function (data) {
      console.log('i got something');
server.on('error', function (e) {
console.log('Server listening on Port 3000');



The problem here is that you're telling Socket.IO to listen on a server that does not yet exist, causing an EACCES and therefore not serving the client file. This is what you're doing:

// the HTTP server doesn't exist yet
var io = require('').listen(server);
var server = http.createServer();

And if you saw in your server-side error console, you get this:

info: started
warn: error raised: Error: listen EACCES

To fix this, move your listen function to after the server is created:

var server = http.createServer();
var io = require('').listen(server);

Once Socket.IO listens properly, it will automatically serve the client file to / You don't need to find it or serve it manually.


The client file that you need is located inside the node_modules folder here:

node_modules/ should serve this file though so you don't need to copy it somewhere else. For example if you are running your server on:


Then the script will be served from:


If you are consuming from another application or another port the relative URL in your code example won't work. You'll want to include the client-script manually or try including the client node module (if consumed by node app).

You can view the client repository here for more info:


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.