1

Hey Guys I have been testing the water with node.js and I wrote a simple web-server program by Ryan Dahl.

//web-server.js
var http= require('http');
http.createServer(function(req,res){
   res.writeHead(200, {'content-type':'text/plain'});
   res.end("helo world \n");
});

s.listen(8000);

Weirdly, I get this error

enter image description here

As you can see, the first command is node-webserver.js The second command is where the error is displayed

I do know however that node.js is not broken because the basic introductory program provided on the node.js still works as it is supposed to. Sorry for the massive error screenshot!

Thanks for any help!

8
  • What's s.listen(8000) - a typo? Commented Jul 10, 2012 at 21:19
  • What server? You didn't assign anything to s variable. Usually it's written as http.createServer(function(req, res){...}).listen(8000); (chaining calls). Commented Jul 10, 2012 at 21:32
  • tried it...still got the same error however the error isnt particular to only this program even this tutorial didnt work simonhampshire.wordpress.com/tag/websockets-node Commented Jul 10, 2012 at 21:36
  • 1
    Erm... I'm sorry if it sounds stupid, but what text editor you've used to create this file? Commented Jul 10, 2012 at 21:39
  • wordpad :/ i have noticed that notepad adds weird formatting after compilied by node Commented Jul 10, 2012 at 21:39

2 Answers 2

1

Your file is apparently saved as a RTF file, while it needs to be saved as plain text.

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

Comments

1

This is the time when error message actually means something: {\rtf1\ansi\ansi is not a valid JavaScript code. And this is the line which was inserted by your text editor.

And, please, please, please, don't EVER use WordPad for editing code. There's plenty of good and free text editors/IDE around here: I personally use Geany for little tasks, and NetBeans for big projects. I suppose you might try Visual Studio Express, too (it's free, unlike its bigger brothers). And there's also such a nice thing as Notepad++.

But using WordPad for writing code is just like using a chainsaw to nail a shelf, in my opinion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.