Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js keeps hanging/loading on localhost

Node.js keeps hanging/loading on localhost

Problem

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?

Problem courtesy of: kevinius

Solution

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);
Solution courtesy of: tfogo

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js keeps hanging/loading on localhost

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×