P K
P K

Reputation: 10210

process.nextTick error in node.js?

enter image description here

I am getting process.nextTick error on this very basic example of node.js.

Can someone please figure out? Is node not able to start listening on port 8000?

# cat nodejs.js
net = require("net");
s = net.createServer();

net.on('connection', function (c) {
c.end('hello');
});

s.listen(8000);

# node nodejs.js

node.js:201
    throw e; // process.nextTick error, or 'error' event on first tick
          ^
TypeError: Object #<Object> has no method 'on'
at Object.<anonymous> (/home/ec2-user/praveen/nodejs.js:4:5)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Array.0 (module.js:470:10)
at EventEmitter._tickCallback (node.js:192:40)

Upvotes: 5

Views: 13959

Answers (3)

grumpit
grumpit

Reputation: 187

For anyone else who might stumble here looking for why node pukes this error when they try to issue brunch watch --server, check and make sure you don't have any other servers running using the same port (i.e. in another shell).

Upvotes: 1

danmactough
danmactough

Reputation: 5484

It's a typo in Ryan's slide! :-0

s/net.on/s.on/

Upvotes: 10

sczizzo
sczizzo

Reputation: 3206

It seems you're trying to capture an event on the library (net), but you should be looking at the connectionListener argument to createServer. Try this instead:

var net = require("net");

var server = net.createServer(function (c) {
  c.end('Hello!'); // Implicitly fired on 'connection'
});

server.listen(8000);

Upvotes: 4

Related Questions