Created
November 16, 2011 23:57
-
-
Save silentrob/1371921 to your computer and use it in GitHub Desktop.
Simple Node static Server
This file contains hidden or 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
#!/usr/bin/env node | |
var express = require("/Users/ironman/.node_libraries/express"); | |
var startPort = 4567; | |
var app = express.createServer(); | |
app.configure(function(){ | |
app.use(express.static(process.cwd() + '/')); | |
app.use(express.directory(process.cwd() + '/',{ icons:true })); | |
}); | |
// Support multiple static apps running | |
function tryToListen(port) { | |
try { | |
app.listen(port); | |
return port; | |
} catch(e) { | |
return false; | |
} | |
} | |
var port = tryToListen(startPort); | |
while (port == false) { | |
port = tryToListen(startPort++); | |
} | |
console.log("Listening on port", port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment