As this blog entry by Eric, it is ridiculously easy to get a node.js server setup and responding to requests on 127.0.0.1:#port#
.
Really easy. I just did it all in... Longer than write this text.
Download an OS-appropriate node.js1: http://nodejs.org/
Now, create a .txt
(plaintext) file in the same folder as your node.exe
and rename that to server.js
.
Put this Javascript in that file:
var http = require('http');
http.createServer(function (request, response) {
console.log('request starting...');
response.writeHead(200, { 'Content-Type': 'text/html' });
var html = '<p>Hello World!</p>';
response.end(html, 'utf-8');
}).listen(8125);
console.log('Server running at http://127.0.0.1:8125/');
Open a cmd.exe
and cd c:\path\to\the\node\executable
, where node.exe
resides.
From there, run:
node server.js
You should see it say:
Server running at http://127.0.0.1:8125
Open a browser and put http://127.0.0.1:8125/
in the address bar.
You should see it say:
Hello World!
That's it. That's pretty easy. The proverbial Hello World!
in 15 seconds or less. Now how to get it to parse a Javascript file and return that output instead of simple HTML...
1. Note, I got the executable, node.exe
, made a folder somewhere, put the executable in that folder. No installer. Works like a charm.