I'm following this beginner node.js tutorial ( http://debuggable.com/posts/understanding-node-js:4bd98440-45e4-4a9a-8ef7-0f7ecbdd56cb ) and i have just created my first server using this code:
var http = require("http")
http.createServer(
function(request, response){
response.writeHead(200, {"Content-Type":"text/plain"})
response.write("hello world")
response.end
}
).listen(3333)
This works great, but when i go to the url localhost:3333/ i see the words "hello world" very briefly and then it just dissapears.
See this vine for a quick video: https://vine.co/v/MBJrpBEQvLX
Any ideas?
Put your Hello World in the response#end() . I'd also suggest that your read the NodeJS API
http.createServer(function (req, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(3333);
You forgot to put parentheses at the end of response.end()
.
The code should read:
var http = require("http");
http.createServer( function(request, response){
response.writeHead(200, {"Content-Type":"text/plain"});
response.write("hello world");
response.end();
}).listen(3333);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.