A couple of trivial Web servers that run on the Node.js platform.
Created
May 11, 2010 01:50
-
-
Save textarcana/396809 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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