【问题标题】:Executing javascript code with node.js使用 node.js 执行 javascript 代码
【发布时间】:2011-06-18 16:58:24
【问题描述】:

我正在尝试使用 node.js 执行 javascript 代码,但总是出现两个错误:

.port 1 未激活

.port 2 未激活

这是我的 javascript 代码:

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

有什么想法吗?

【问题讨论】:

  • 顺便说一下我在ubuntu下,我用node myscript.js编译。
  • 很奇怪它应该可以工作。我将使用我之前的示例正确重新安装节点。我认为它彻底解释了它stackoverflow.com/questions/4441798/…
  • 尝试localhost 而不是127.0.0.1 听起来您的路由器设置方式等存在问题
  • 总是遇到同样的问题,即使在通过 localhost 更改 127.0.0.1 之后也是如此
  • @Raynos 这个例子对我有用。 $node -v 0.2.6 应该的!

标签: javascript linux compiler-construction ubuntu node.js


【解决方案1】:

您是否已经在 8124 上收听了其他内容?

netstat -an|grep :8124

【讨论】:

    猜你喜欢
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2011-04-03
    • 1970-01-01
    • 2020-02-29
    相关资源
    最近更新 更多