如何使用Node.js运行用js编写的服务器
我已经从这里.js。在我的Windows8机器上。将示例服务器代码复制到我的server.js文件中
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/');
然后打开node.js提示符,并写入节点c:/node/server.js但什么也没发生。我是一个PHP开发人员,只是想尝试一下它,任何指导原则都将对您有所帮助。
回答如下:您不需要进入node.js提示符,只需要使用标准命令promt并编写
node c:/node/server.js
这也有效:
node c:\node\server.js
然后在浏览器中:
http://localhost:1337
如何使用Node.js运行用js编写的服务器
我已经从这里.js。在我的Windows8机器上。将示例服务器代码复制到我的server.js文件中
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/');
然后打开node.js提示符,并写入节点c:/node/server.js但什么也没发生。我是一个PHP开发人员,只是想尝试一下它,任何指导原则都将对您有所帮助。
回答如下:您不需要进入node.js提示符,只需要使用标准命令promt并编写
node c:/node/server.js
这也有效:
node c:\node\server.js
然后在浏览器中:
http://localhost:1337