Get into DevOps is a blog about methodologies, practices and tools to improve software delivery.

How to expose your local Node/Django/Rails/Flask development server on the Internet

How to expose your local Node/Django/Rails/Flask development server on the Internet

In this post I'll show you how to expose a locally running development server on the Internet. This is something I use often to run external tests against an app I'm building with Python and Flask.

I'll be using Dyname, which is a free service I built recently. The particular feature that will allow external access to my local server is called Developer mode.

First, let's go through how to start the local development server for some common web application frameworks:

Start the Flask development server

With Python and Flask, when my main server code is in server.py (ie. the file with run() call), I'm running the usual local development server as follows:

python server.py

Please note that the server listens to 127.0.0.1, and is not bound to all interfaces with 0.0.0.0. This is expected; Dyname's Developer mode will work around this.

Start the Node.js development server

If I were writing a Node.js application, I would start the development server with the following command:

node server.js

Where server.js is the file with the server.listen() call.

Start the Django development server

Django is a brilliant web application development framework for Python. If you haven't seen it, I highly recommend you take a look: https://www.djangoproject.com

When using Django, I'll start the local development server as follows:

python manage.py runserver

Start the Ruby on Rails development server

With Rails, the development server is started with the following command:

bin/rails server

Expose the development server publicly

As I mentioned above, I will be using Dyname's Developer mode to create an easy to remember hostname and point it to my local development server.

Assuming you're running Mac OS X or Linux, this all happens with a single command:

bash <(curl -sL https://get.dyname.net)

If you don't have curl installed, try running this instead:

bash <(wget -qO- https://get.dyname.net)

The interactive setup will guide you through selecting a hostname (ending in .dyname.net or .dnm.li). The setup scripts are also available in Github.

When the interactive setup asks you for operating mode, be sure to enter 2 for Developer mode:

Dyname has two operating modes:

1) Traditional Dynamic DNS, where the hostname is pointed to your IP address.
2) Developer mode, which exposes any development HTTP server on your local machine to your hostname, even if you are behind NAT or a firewall.

Choose operating mode [1]: 2

You will also need the local port your development server is running on. By default, it's 5000 for Flask, 3000 for Rails, 8000 for Django and either 3000 or 8080 for Node.js. The output from starting the development server will tell you the correct port.

Here I'm pointing Developer mode to port 3000 for a Ruby on Rails development server:

Which local port would you like to expose via my-dev-server.dyname.net?
Local port [5000]: 3000

Once you're all set, you will get the following output:

Dyname Developer mode is now forwarding http://my-dev-server.dyname.net to your local port 5000. Press ENTER to quit ...

Your local development server is now accessible via the hostname you chose (in this example http://my-dev-server.dyname.net) - and you can share the URL to your friends and colleagues. To close Developer mode, just press ENTER.

If you use this feature in your work, for example to present your work to clients, you could look into associating your own domain name with Dyname. It's free (assuming you already have the domain), and you get a nice URL for your development server, such as http://dev.mydomain.com.

Pro tip: The Dyname setup saves its settings in your home directory. When you next run the setup command, it'll ask if you want to repeat what you did the last time. Just press ENTER:

$ bash <(curl -sL https://get.dyname.net)
Would you like to repeat your last action (point my-dev-server.dyname.net to your local port 5000)? y/n [y]

Pro-pro tip: Once you've run Dyname once, you can start Developer mode automatically with just a single command by passing the UNATTENDED variable:

$ UNATTENDED=1 bash <(curl -sL https://get.dyname.net)
Dyname Developer mode is now forwarding http://my-dev-server.dyname.net to your local port 5000. Press ENTER to quit ...

I hope you find the tool useful. All feedback is welcome - please drop me a line at miiro.juuso@gmail.com, or as a comment in this post.

Read next: How to use a custom domain name with AWS EC2 instances

Getting started with AWS: Guide for developers

How to use a custom domain name with AWS EC2 instances

How to use a custom domain name with AWS EC2 instances