-1

I've been looking online and have found that the stuff about SSJS is a bit confusing. How do I get started with Server-Side JavaScript? Can it be used with any web host?

So far, I've downloaded the Node.js program from the official website, installed it, setup PATH (which the installer does) and I've copied/pasted the code snippet:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

that is displayed on the main page into example.js, then opened the node cmd and entered: "node.js example.js" (without quotes) and all I get in return is:

...

But I should be getting:

"Hello, world!"

Am I doing something wrong?

3
  • Go the browser and go to http://127.0.0.1:1337/ and see what you're getting. You should get Hello Word there. Commented Dec 4, 2014 at 9:10
  • @VarunAchar Sorry, "This page cannot be displayed." :/
    – jay_t55
    Commented Dec 4, 2014 at 9:12
  • the book called Learning Node.js is pretty good. Commented Jan 15, 2015 at 15:28

1 Answer 1

0

I think your command line should just be 'node example.js'

2
  • thanks for your answer. That doesn't work either though. All I get in the (node) cmd window is "...", and in the browser I get "This page cannot be displayed."
    – jay_t55
    Commented Dec 4, 2014 at 9:14
  • Save this code in test.js or something else and on cmd do this node test.js without any quotes and paste 127.0.0.1:1337 on browser press enter and that's it
    – abdulbari
    Commented Dec 4, 2014 at 11:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.