Skip to content

Instantly share code, notes, and snippets.

@textarcana
Created May 11, 2010 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textarcana/396809 to your computer and use it in GitHub Desktop.
Save textarcana/396809 to your computer and use it in GitHub Desktop.

A couple of trivial Web servers that run on the Node.js platform.

/*global require get run */
/*
Create Web service using Express
First, install Express:
git clone git://github.com/visionmedia/express.git && cd express && git submodule update --init
*/
require.paths.unshift('express/lib');
require('express');
var sys = require('sys');
get('/', function(){
this.redirect('/hello/world');
});
get('/hello/world', function(){
var msg = 'Hi World'
var template = function (content){
return '<html><head><title>' +
msg +
':A Tiny Web Service</title><body><h1>' +
msg +
'</h1><hr>Rendered with Node.js</body></html>';
};
sys.log(msg);
return template(msg);
});
run();
require 'rake'
desc 'install the Express Web application framework'
namespace :install do
task :express do
system %{
git clone git://github.com/visionmedia/express.git && cd express && git submodule update --init
}
end
end
/*
Create Web service with Node.js
*/
var sys = require('sys'),
http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(9000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment