Node.js throw e error -


i messing around in node.js trying replicate simple chat server floating around.

this javascript source file:

var net = require('net'); var carrier = require('carrier');  var connections = [];  var server = net.createserver(function(conn) {     connections.push(conn);      conn.on('close', function() {         var pos = connections.indexof(conn);         if (pos >= 0) {             connections.splice(pos, 1);         }     });      conn.write("hello, welcome chat server!\n");     conn.write("please input user name:\n");      var username;      carrier.carry(conn, function(line) {         if(!username) {             username = line;             conn.write("hello " + username + "!\n");             return;         }          if(line == 'quit') {             conn.end();             return;         }          connections.foreach(function(one_connection) {             one_connection.write(line);         }); });  server.listen(8000); 

as far can tell, in here correct.

now, when try run through node.js, following:

script.js:39 });  node.js:134     throw e; 

there stuff follows, don't understand node.js referencing line 39, doesn't exist. it's 38-lined script last line being:

server.listen(8000); 

so, doing wrong?

i'm sorry if simple, i'm new @ this, , it's kind of daunting.

thanks!

you're missing set of }); @ bottom. it's complaining that.

from indentation, it's carrier.carry(conn, function(line) {

i suggest getting editor can point out matching parens / braces (e.g. textmate on mac or editplus on windows)


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -