-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?

jay_t55
  • 11,362
  • 28
  • 103
  • 174

1 Answers1

0

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

William Moore
  • 246
  • 2
  • 16
  • 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 Dec 04 '14 at 09:14
  • Save this code in test.js or something else and on cmd do this node test.js without any quotes and paste http://127.0.0.1:1337/ on browser press enter and that's it – abdulbarik Dec 04 '14 at 11:13