M
M
Marat Mkhitaryan2016-03-29 06:48:04
Node.js
Marat Mkhitaryan, 2016-03-29 06:48:04

What is my error in the code?

Guys tell me what is my mistake in the code:

// Including libraries

var app = require('http').createServer(handler),
  io = require('socket.io').listen(app),
  static = require('node-static'); // for serving files

// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server('./');
  
// This is the port for our web server.
// you will need to go to http://localhost:8080 to see it
app.listen(80);

// If the URL of the socket server is opened in a browser
function handler (request, response) {

  request.addListener('end', function () {
        fileServer.serve(request, response);
    });
}

// Delete this row if you want to see debug messages
io.set('log level', 1);

// Listen for incoming connections from clients
io.sockets.on('connection', function (socket) {

  // Start listening for mouse move events
  socket.on('mousemove', function (data) {
    
    // This line sends the event (broadcasts it)
    // to everyone except the originating client.
    socket.broadcast.emit('moving', data);
  });
});

when compiling (running through nodejs) gives an error in the console
module.js:340     throw err;           ^ Error: Cannot find module '/root/app/app/app.js'     at Function.Module._resolveFilename (module.js:338:15)     at Function.Module._load (module.js:280:25)     at Function.Module.runMain (module.js:497:10)     at startup (node.js:119:16)     at node.js:902:3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Vinnichenko, 2016-03-29
@HollaOut

Did you provide the correct path? And then I somehow doubt that it is exactly like this: '/root/app/app/app.js'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question