Node.js closes as I open it

I am running a very simple script in nodejs, loading a static html file.

var http = require("http");
fs = require('fs');

fs.readFile('./index.html', function (err, html) {
    if (err) {
        throw err; 
    }       
});

http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}).listen(1994);

Whenever I launch the application it immediately closes. I see the text on the console for the half second that the application launches, but then the window closes. This happens every time.

You are most probably using the Node.js repl which comes with any installation of Node.js.

I get no errors when I run your code (assuming I have index.html in my directory and no error is thrown).

Try to run your code via the command line with the commandnode yourscriptfilename.js

After uninstalling and re-installing nodejs, and then updating the problem was solved. I think that it was simply node being new to windows with a few unaccounted for issues. The problem was a few months ago, so I forget the exact specifics. Using command prompt shells in windows leads to problems (as one can imagine.)