Skip to content

Instantly share code, notes, and snippets.

@acidsound
Last active April 29, 2016 04:32
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 acidsound/4414368 to your computer and use it in GitHub Desktop.
Save acidsound/4414368 to your computer and use it in GitHub Desktop.
require('http').createServer((q,r)->require('fs').readFile(process.cwd()+q.url,(e,d)->r.end if e? then JSON.stringify(e) else d.toString())).listen 3000 or process.env.PORT
var http=require('http');
var fs=require('fs');
http.createServer(function(req, res) {
console.log(
"["+Date.now()+"]"+
"METHOD:"+req.method+
" | URL:"+req.url
);
fs.readFile(req.url==='/' && 'index.html' || process.cwd()+req.url, function(err, data) {
res.write(err && JSON.stringify(err) || data.toString());
res.end();
});
}).listen(process.env.PORT or 3000);
require 'http'
.createServer (q,r) ->
console.log "[#{new Date().toISOString()}]#{q.method}: #{q.url}"
require('fs').readFile process.cwd()+q.url, (e,d)->
r.end if e? then JSON.stringify(e) else d.toString()
.listen process.env.PORT or 3000
require('http').createServer((q,r)=> {
console.log(`[${new Date().toISOString()}]${q.method}: ${q.url}`);
require('fs').readFile(process.cwd()+q.url, (e,d)=> {
r.end(e && JSON.stringify(e) || d.toString());
});
}).listen(process.env.PORT || 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment