Skip to content

Instantly share code, notes, and snippets.

@brenapp
Last active November 17, 2016 02:01
Show Gist options
  • Save brenapp/98ccf4c976ef5f3b959be4f8ac228c31 to your computer and use it in GitHub Desktop.
Save brenapp/98ccf4c976ef5f3b959be4f8ac228c31 to your computer and use it in GitHub Desktop.
npm i -g express & curl -o /usr/local/bin/serve https://gist.githubusercontent.com/MayorMonty/98ccf4c976ef5f3b959be4f8ac228c31/raw/e895f30bf37858b52f92ad285eeafc35a2087549/serve.js
#!/usr/bin/env node
var express = require("express"),
path = require("path"),
fs = require("fs"),
app = express(),
root = path.resolve(process.argv[2] || process.cwd());
app.use(function(req, res, next) {
console.log(`${req.method} ${req.url} `);
next();
});
app.use(express.static(root));
app.use(function(req, res) {
res.end("Your request could not be handled.");
});
var port = process.argv[4] || 3000,
ip = process.argv[3] || "0.0.0.0";
app.listen(port, ip, 511, function() {
console.log(`Serving ${root} at ${ip}:${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment