node xsp用于nodejs

时间:2013-02-03 22:12:29

标签: node.js

为什么我在Apache Web服务器上看到以下页面

显示页面代码?

http://localhost/main.js

我安装Windows Installer

我正在运行命令提示符中编写的所有代码 但是这段代码无法在浏览器中看到

换句话说,

如何在浏览器中运行nodejs代码?


更新

我的代码:

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

1 个答案:

答案 0 :(得分:0)

首先关闭.. Apache与节点无关。

通过运行node main.js启动main.js文件,然后导航到节点服务器正在运行的位置(假设main.js实际上创建了一个Web服务器)。检查main.js中的端口和主机名。应该是这样的:http://localhost:8000

相关问题