Mini server using netcat

Categories: Blog

I was trying to run some tests with lighthouse and was looking for the most simple webserver that I could get just to check what the report would look like, so I didn’t want to run apache locally or a simple nodejs or python script I was looking for the most bare bones thing that I could find and I ended up thinking about netcat and sure enough, it did the job, if you are ever looking for a simple webserver and you don’t want to install the whole thing for whatever reason you can just use this:

while true; do echo -e "HTTP/1.1 200 OK\r\n\n$(date)" | nc -vlN 8080; done

This of course will return the date if you visit localhost:8080 but you can change it to do more complex stuff or maybe return the content of a real HTML file, the sky is the limit!

«
»