Front End Pro Tip:

View Localhost On Devices In Your Network

Often when I am working on localhost I want to test my work on other devices within my network. I typically would run ifconfig in the terminal and peer through the lines of returned text for the the word broadcast then use the IP address from that line. Wanting an easier solution I put together the following shell script.

localIp() {
  ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -2 | tail -1

I use zsh for my shell and have this housed in my ~/.zshrc file. Implementation is pretty straight forward. I also use Atom most often for my editor

  • Open your config file atom ~/.zshrc
  • Place in the function under the # User configuration line
  • Reset available commands without needing to quit or restart terminal source ~/.zshrc

Now you can run localIp and you should see something like this.

Return Localhost Broadcast IP Address

Lastly to run localhost on other devices load up the returned Ip address on your browser and optionally append the port or path you were working with before.