1

I had installed node by following article https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29

Now i had made a test.js file in c:/cygwin/home/adminstrator/test.js here my node folder is present.

My test.js file is

var sys = require("sys"), http = require("http"); http.createServer(function(request, response) { response.sendHeader(200, {"Content-Type": "text/html"}); response.write("Hello World!"); response.close(); }).listen(8080); sys.puts("Server running at http://localhost:8080/"); 

But in browser if run localhost:8080 or 8.8.8.8:8080 the content is not displaying ("hello world ")

Please suggest what should i do ?

Edit Error while running command

$ node /home/Administrator/test.js Server running at http://localhost:8080/ /home/Administrator/test.js:5 response.sendHeader(200, {"Content-Type": "text/html"}); ^ TypeError: Object #<a ServerResponse> has no method 'sendHeader' at Server.<anonymous> (/home/Administrator/test.js:5:15) at Server.emit (events.js:27:15) at HTTPParser.onIncoming (http.js:871:14) at HTTPParser.onHeadersComplete (http.js:88:31) at Stream.ondata (http.js:792:22) at Stream._onReadable (net.js:762:27) at IOWatcher.onReadable [as callback] (net.js:276:10) 
2
  • Have you started node.js using node /home/adminstrator/test.js command from cygwin console? Commented Feb 3, 2011 at 10:55
  • @actual if i do node test.js it show the output of sys.puts("Output") funciton. but how to run in browser respose.write ? Commented Feb 3, 2011 at 10:58

1 Answer 1

3

The methods .sendHeader() and .close() don't exist. You wan't .writeHead() and .end() instead.

Reference: http://nodejs.org/docs/v0.3.7/api/http.html#http.ServerResponse

Sign up to request clarification or add additional context in comments.

4 Comments

@Box9 But how to open in browser ?
@Rahul, sorry I missed that part. In cygwin type: node /home/administrator/test.js, then direct your browser to localhost:8080.
@Rahul, no, apache is completely different. You say that you see the message "Server running at..." in Cygwin? Do you see anything else? (Both before and after you put "localhost:8080" into your browser.
@Rahul, that's because sendHeader doesn't exist either. I've updated my answer with the correct method, but please check the documentation I linked to!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.