Jestem nowy dla nodeJS i triyng, aby go poznać.
Próbuję wykonać przykład Witaj świecie z http://net.tutsplus.com/tutorials/javascript-ajax/node-js-for-beginners/ , ale nie otrzymuję żadnych danych wyjściowych i otrzymuję Brak strony otrzymanych danych w przeglądarce Chrome.
Mam zainstalowany apache (XAMPP) na moim komputerze, ale nie jest aktywny, a także gdy próbuję uruchomić node http.js
w terminalu nie otrzymuję żadnych danych wyjściowych.
Mam jeszcze jeden plik hello.js, który zawiera console.log('Hello World!');
po uruchomieniu node hello.js
otrzymuję wyjście Hello World!
w terminalu. Ale http.js
nie działa.
http.js Kod:http: // localhost: 8080/nie działa
// 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);
Czy pojawiają się błędy w konsoli? Jakieś wskazówki co do tego, co się dzieje? Ten kod działa dobrze dla mnie, gdy idę do localhost: 8080 w przeglądarce. Czy próbowałeś wpisać: http://127.0.0.1:8080 w przeglądarce? Zarówno http://127.0.0.1:8080 i http: // localhost: 8080 działają dla mnie w mojej przeglądarce .. ale musisz podać port 8080 w url. – thtsigma
używasz proxy? –
Nie ma błędu w konsoli. Nie użyłem tutaj serwera proxy. –