Starting a node.js server


Question

I recently got into node and I installed it on my localhost. I am using WAMP. I am on Windows Vista.

Anwyay, I installed it. I made a new file in my localhost directory with this being called server.js

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {
        'Content-Type': 'text/plain',
        'Access-Control-Allow-Origin' : '*'
    });
    response.end('Hello World\n');
}).listen(1337);

then I went to node and tried typing % node server.js and all I got was an ellipses. What gives?


UPDATE: I checked my Systems variable and saw that my PATH lists the node.js as C:\Program Files (x86)\nodejs\

enter image description here

1
23
5/14/2012 7:02:15 AM

Accepted Answer

Run cmd and then run node server.js. In your example, you are trying to use the REPL to run your command, which is not going to work. The ellipsis is node.js expecting more tokens before closing the current scope (you can type code in and run it on the fly here)

47
5/15/2012 6:35:11 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon