Hacker News new | past | comments | ask | show | jobs | submit login

I'm surprised there's no one-liner for Node without dependency since it has a server by default.

Edit: Didn't know there was an `eval` flag for Node, so that will do the job:

node --eval "var fs = require('fs'), http = require('http'); http.createServer(function (req, res) { fs.readFile(__dirname + req.url, function (err,data) { if (err) { res.writeHead(404); res.end(JSON.stringify(err)); return;}res.writeHead(200);res.end(data); });}).listen(8080);"




Doesn't protect against folder climbing/traversal like `curl :8080/../../etc`.


Huh .. that'd be a fun post; see how many of these can be susceptible for climbing out of their web root. The author does list which ones support dir indexes.


hopefully you're not using a one-liner for your actual deployment. I use it for no stakes development


Caddy is a one-liner. Plenty of the one-liners are suitable for production. There are so many solutions that you might as well use one, even in development, that doesn't have such glaring issues, because you're basically training your muscle memory to reach for it.


Most of these one-liner probably aren't secure. As the title post says "Use this power wisely".


npx http-server -p 8080




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: