Can not Run Node.js server file -


I am new to node. Js. I have a nodesaver.js file which is below the code.

  var requires Express = ("Express"); var app = express (); Var ports = 60000; Var io = requires ('socket.io'). Listen (app.listen (port)); Console.log ("listen on ports" + port); Io.sockets.on ('connection', function (socket) {socket.emit ('message', {message: 'welcome to chat'}); socket.on ('send', function (data) {io Sockets.emit ('Message', Data);});});   

When I run it from the command prompt, under the code

  D: \ path for my application> node node server. Js   
  information - socket.io started listening to port 6000   

but when I try to connect to this port By the browser, it shows me the error below at the command prompt

  D: \ path my application \ node_modules \ expres S \ lib \ application.js: 119 this._router.handle (req, res, function (err) {^ typeError: undefined method 'handle' can not call   

What do I do Am I wrong?

The problem has been solved:

Below me The edit is

Below is my client script

  $ (document) ready (task () (var socket = io.connect ('http: //127.0. 0.1: 60000 ');});   

Below is my country

  & lt ;! DOCTYPE html public "- // W3C // DTD XHTML 1.0 Transcription // n "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" target="http://www.w3.org/1999 / Xhtml "& gt; & lt; Head runat = "server" & gt; & Lt; Script src = "jquery-1.10.1.min.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script src = "http://127.0.0.1:60000/socket.io/socket.io.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; script src = "NodeClient.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Div & gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

When I run my application, I get the error of "network error: 404" - http://127.0.0.1:60000/socket.io/socket.io. Js "

I have solved my problem with the following steps.

  1. I moved my client script to a specific folder (script). (My client script name is NodeClient.js)
  2. I deleted app.get ("/", function (req, res)) {your logic should go here}); Server script from the function.
  3. Code app.use was added below (express.static (__dirname + '/ scripts'));

    Now it is working the way I want it. I do not know whether this is true or not, but it is working for me now.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -