私はnodeJSが初めてで、それを学ぼうとしています。http://net.tutsplus.com/tutorials/javascript-ajax/node-js-for-beginners/
から hello world の例を実行しようとして
いますが、出力が得られず、クロムで No data received ページが表示されますブラウザ。
PC に apache (XAMPP) をインストールしましたが、アクティブではなく、ターミナルで実行しようとしても出力が得られません。
私は別のファイルhello.jsを持っています。これには
、実行時に端末に出力が表示されます。しかし、機能していません。
http.js コード:node http.js
console.log('Hello World!');
node hello.js
Hello World!
http.js
// Include http module.
var http = require("http");
// Create the server. Function passed as parameter is called on every request made.
// request variable holds all request parameters
// response variable allows you to do anything with response sent to the client.
http.createServer(function (request, response) {
// Attach listener on end event.
// This event is called when client sent all data and is waiting for response.
request.on("end", function () {
// Write headers to the response.
// 200 is HTTP status code (this one means success)
// Second parameter holds header fields in object
// We are sending plain text, so Content-Type should be text/plain
response.writeHead(200, {
'Content-Type': 'text/plain'
});
// Send data and end response.
response.end('Hello HTTP!');
});
// Listen on the 8080 port.
}).listen(8080);