---
title: Dat's Incredible!
content_type: journal
date_pub: 2018-10-11T12:03:00-04:00
date_upd: 2018-12-01T12:23:00-05:00
tldr: I decided to try out the Dat protocol, and now have a copy of this site <a href='dat://3dccd6e62ea8e2864fb66598ee38a6b4f4471137eebc23ddff8d81fc0df8dbbc'>running on it</a>.
tags: dat archive WebDev
---

Recently, I was inspired by [Aral Balkan's concept of Web+](https://ar.al/2018/06/26/web+/) and [his work with dats](https://ar.al/2018/06/25/demonstrating-web-plus-dat/) to add [Dat protocol support](https://datproject.org/) to my own site(s). Since my experiences might be useful to others, I thought I'd share them here.

A #dat, or Dat #archive (as I understand it) is a sort-of cross between a [Git](https://en.wikipedia.org/wiki/Git) repository and [BitTorrent](https://en.wikipedia.org/wiki/BitTorrent) file share. It was initially developed for storing and sharing data in a decentralized way, and so makes for a great way to share an archive of static content (like a website).

To create and share a Dat archive, I needed to install the Dat protocol. Since it uses [NodeJS](https://nodejs.org/), this is done via the [Node Package Manager](http://npmjs.com/):

```shell
sudo npm install -g dat
```

I already had a directory in mind to share (the directory that holds the static files of my website), so sharing the dat was as simple as: going into that directory and typing the following commands:

```shell
# Enter the directory with the static files
> cd www

# Create the dat
> dat create

Welcome to dat program!
You can turn any folder on your computer into a Dat.
A Dat is a folder with some magic.

Your dat is ready!
We will walk you through creating a 'dat.json' file.
(You can skip dat.json and get started now.)

Learn more about dat.json: https://github.com/datprotocol/dat.json

Ctrl+C to exit at any time
Title: It's Eric Woodward (dotcom)
Description: Dat for the site running at https://www.itsericwoodward.com/.
Created empty Dat in /home/eric/www/.dat

Now you can add files and share:
* Run dat share to create metadata and sync.
* Copy the unique dat link and securely share it.

dat://3dccd6e62ea8e2864fb66598ee38a6b4f4471137eebc23ddff8d81fc0df8dbbc

# Share the newly-created dat
> dat share
```

And that's it. :)

To verify that I was sharing it, I pointed my web browser to https://datbase.org/, entered my DAT URL in the search box at the top-left of screen, pressed ENTER, and, lo and behold, my website came up.

Another way to verify that a DAT URL is being actively shared is to view it through the [Beaker Browser](https://beakerbrowser.com/), a special web-browser-like application used for viewing dats. To get it, I went to https://beakerbrowser.com/install/, and downloaded the [AppImage](https://appimage.org/) file for Linux (no link provided here because the Beaker Browser still in pre-release, and any image that I point to from here will probably be old by the time anyone reads this).

Then, I launched it:

```shell
# Make it executable

> chmod a+x beaker-browser-0.8.0-prerelease.7-x86_64.AppImage

# Launch the AppImage

> ./beaker-browser-0.8.0-prerelease.7-x86_64.AppImage
```

After a few moments, the application came up, at which point I entered my dat URL into the Beaker Browser's address bar, hit the ENTER key, and just like that, my website came up.

Unfortunately, unless your data is wildly popular (and thus located across multiple hosts in the [swarm](https://docs.datproject.org/hyperdiscovery)), it is only shared for as long as the `dat share` command is running on your machine. So, to make the files permanently available via Dat, I had to create a service file that would run the `dat share` automatically. To do this, I created file in `/etc/systemd/system` called `dat-share-web.service`, which looked like this:

```shell
[Unit]
Description=DAT Share for It's Eric Woodward (dotcom)
After=network.target

[Service]
User=eric
Type=simple
WorkingDirectory=/home/eric/www
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStart=/usr/bin/node /usr/local/lib/node_modules/dat/bin/cli.js share
Restart=always

# Output to syslog
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=dat-share-www

[Install]
WantedBy=multi-user.target
```

After I turned-off my existing DAT share, I started the new service, like this:

```shell
# Start the service
> sudo systemctl start dat-share-www

# Enable the service
> sudo systemctl enable dat-share-www
```

Now, my Dat archive will be served 24x7, even after I restart the server.

Everything worked great, but there was one more thing that I wanted to try: I had noticed that, in addition to Aral's site being available at a usual DAT address (`dat://` plus a 64-charactercode), it was also available at his own domain name (dat://ar.al/). After a quick search, I found that what I was looking for was [DAT over DNS](https://www.datprotocol.com/deps/0005-dns/), which can be implemented one of two ways: either via [DNS TXT records](https://github.com/beakerbrowser/beaker/wiki/Dat-DNS-TXT-records-with-optional-DNS-over-HTTPS) or by [placing a file with a link to the DAT at a specific "well known" location](https://github.com/beakerbrowser/beaker/wiki/Authenticated-Dat-URLs-and-HTTPS-to-Dat-Discovery). Since the second option is the one that the DAT project seems to recommend (and it was dead simple to add), [that's what I did](/.well-known/dat). So now, if you launch the Beaker Browser and open the site `dat://www.itsericwoodward.com/`, it will take you to the DAT version of my site. Neat!

The DAT protocol is a simple but powerful way to share static content, and can help add a layer of redundancy to a website. Hopefully, your experiences in using it will be as positive as mine.

References:

+ https://docs.datproject.org/install
+ https://docs.datproject.org/tutorial
+ http://awesome.datproject.org/
+ https://forum.ind.ie/t/running-a-dat-share-as-a-service-with-systemctl-ubuntu-etc/2181
