
我在node.js这个非常基本的例子中得到process.nextTick错误
有人可以搞清楚吗?节点无法开始侦听端口8000吗?
# cat nodejs.js
net = require("net");
s = net.createServer();
net.on('connection', function (c) {
c.end('hello');
});
s.listen(8000);
Run Code Online (Sandbox Code Playgroud)
# 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)
Run Code Online (Sandbox Code Playgroud)
您似乎正在尝试捕获库 ( ) 上的事件net,但您应该查看createServer 的 connectionListener 参数。试试这个:
var net = require("net");
var server = net.createServer(function (c) {
c.end('Hello!'); // Implicitly fired on 'connection'
});
server.listen(8000);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13057 次 |
| 最近记录: |