One liner server command in ruby

in #ruby7 years ago

Have you ever wondered whether ruby has one liner server command equivalent to the python ? Turns out there is a similar command for ruby also.

Open your terminal, go to your desired directory where you want to run the server and enter the following:

ruby -run -e httpd . -p 5000

It will start a webserver runnning on your machine at port 5000. No extra gem is needed for this to run.

Sort:  

Using Ruby and especially Rails for years now I never noticed that WEBrick is already on board on every Ruby installation. And to be honest I am not really sure if that makes sense at all. But nice to know, thanks for the article.

I have been using this server whenever I want to share my local file with my peers in same network. It comes handy sometimes. It's never bad thing to have a useful tool.

BTW I'd love to hear about your experience with rails.

Happy coding @sga

You're right, its not a bad thing. It's just my personal preference that software should focus on its purpose. A webserver as part of a language interpreter seems a bit bulky to me.

I have a software development company in Germany. We develop all kinds of software, e.g. marketing, CRM, e-shops and whatever the client needs. Because most of the software has a web frontend these days we focus on Rails development for five or six years now.

What do you do for living? Ruby, too?

I have a software development company in Nepal mostly focused on outsourcing jobs. We focus on Rails development too.