DEV Community

Cover image for Use hex.docs locally
Byron Salty
Byron Salty

Posted on • Edited on

3 1

Use hex.docs locally

I'm boarding a plane in a few minutes, but I'd like to still have access to hex.docs.

How hard could it be to get docs running locally so I don't need a connection to use them?

...

It turns out to be very, very easy. The Elixir guys thought of everything!

Step 1: Fetch the docs you want

# From any mix directory

mix hex.docs fetch elixir
mix hex.docs fetch kino
mix hex.docs fetch nx
mix hex.docs fetch scholar
mix hex.docs fetch livebook
...
Enter fullscreen mode Exit fullscreen mode

You may need to check the versions and fetch a specific one you're interested in...

mix hex.docs fetch nx 0.5.2
Enter fullscreen mode Exit fullscreen mode

Step 2: Run a local web server from the doc root

On a Mac, the default location for docs is:
/Users/<user>/.hex/docs/hexpm

I use Caddy so with that it's as easy to run a local instance as a single command from the directory:

cd /Users/<user>/.hex/docs/hexpm
caddy file-server --browse --listen :5051
Enter fullscreen mode Exit fullscreen mode

Go to http://localhost:5051 to test.

Bonus step: Create a script for the future

Let's go ahead and automate this. You could create an alias but I prefer to create small scripts that I keep on my PATH to run again whenever needed. In my case, I have a directory at ~/projects/utils

touch ~/projects/utils/local_docs.sh

echo "cd /Users/$(whoami)/.hex/docs/hexpm" > ~/projects/utils/local_docs.sh
echo "caddy file-server --browse --listen :5051" >> ~/projects/utils/local_docs.sh
echo "cd -" >> ~/projects/utils/local_docs.sh

chmod u+x ~/projects/utils/local_docs.sh
Enter fullscreen mode Exit fullscreen mode

Now whenever I want to start my local docs I can just run:

local_docs.sh
Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (1)

Collapse
 
nicholas_moen profile image

Here's a command to start a Python web server so you don't have to download Caddy:

cd /Users/<user>/.hex/docs/hexpm && python3 -m http.server 5051

Bump.sh

Hate writing docs?

Hate undocumented APIs even more?

Bump.sh generates an always up-to-date API reference site for REST and Event-Driven Architectures.

Plug it in your CI. It fetches your OpenAPI and AsyncAPI (GraphQL pending) spec files, and even generates a diff. Gather all of your API docs in a single source of truth.

Try it for free

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay