Skip to content

Instantly share code, notes, and snippets.

@jamsajones
Created August 10, 2015 03:46
Show Gist options
  • Select an option

  • Save jamsajones/86f7c487d2c17eb4e42a to your computer and use it in GitHub Desktop.

Select an option

Save jamsajones/86f7c487d2c17eb4e42a to your computer and use it in GitHub Desktop.
A simple server written in node.
function simple_server {
NODE_PATH=$(which npm |sed -e 's/bin\/npm/lib\/node_modules/')
if [[ $(npm --depth 0 --parseable=true list express 2>/dev/null) = '' ]]; then
npm install -g express 2>/dev/null 1>/dev/null;
fi
if [[ $(npm --depth 0 --parseable=true list json-stringify-safe 2>/dev/null) = '' ]]; then
npm install -g json-stringify-safe 2>/dev/null 1>/dev/null;
fi
node -e "require('express')()\
.disable('etag')\
.all('*',\
function(r,p){\
var s;
try{\
s = require('json-stringify-safe')(r);\
p.type('json');\
p.send(s);\
}
catch (e){\
console.log(e);\
s = e;\
}\
})\
.listen(3030,function(){\
console.log('Server started on http://localhost:3030');\
});"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment