Created
May 3, 2012 22:42
-
-
Save maxired/2590101 to your computer and use it in GitHub Desktop.
A Micro Javascript Page Server à la PHP
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
var express = require('express'); | |
var util = require('util'), | |
spawn = require('child_process').spawn; | |
var app = express.createServer(); | |
app.get('/', function(req, res){ | |
res.send('<ul>' | |
+ '<li>Download <a href="/helloworld.js">Hello world</a>.</li>' | |
+ '</ul>'); | |
}); | |
app.get('/:file(*)', function(req, res, next){ | |
var file = req.params.file | |
, path = __dirname + '/' + file, | |
child; | |
child = spawn(process.execPath, [path]); | |
child.stdout.on('data', function(data){ | |
res.write(data); | |
}) ; | |
child.stderr.on('data', function(data){ | |
res.write(data); | |
}) ; | |
child.on('exit', function(){ | |
res.end(); | |
}); | |
}); | |
app.listen(3000); | |
console.log('Express started on port 3000'); |
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
console.log("Hello World"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment