now – Realtime global deployments
Using Dat, we can turn now's realtime deployment into live deployment.
- Install dat command line or desktop
- Create a new dat with your website files
- Deploy via dat-now via now.sh
- Live sync your website
npm install -g dat
Want to skip installing dat for now and just see how it works? We can use a key for a dat is already being shared.
mkdir file-sharing
cd file-sharing
echo 'hello world' > hello.txt
dat share .
We need to deploy a simple package to hook up our dat to now. We've packaged this up into a npm package called dat-now
and made a demo app you can clone and deploy. dat-now
acts as a bridge between the now http server and files on your computer.
Clone our demo app (this will be deployed to now):
git clone https://github.com/joehand/dat-now-demo.git
cd dat-now-demo
dat-now
reads process.env.KEY
to figure out what files to download & serve. To set this, change the key to your dat key in the now.json
file:
{
"env" : {
"KEY" : "dat://28cddf6d5d21bbd9492dcdba14a68b9a35393b769b15f61e2a5258567d8bca8f"
}
}
(If you want to skip the Dat creation for now, you can also deploy with this key. It'll re-share a dat that is already being shared elsewhere.)
Once we set the key, we can deploy! Use now to deploy the site viua now's realtime global deployment:
cd dat-now-demo
now --public
Visit the site!
The dat-now
package is a really simple wrapper around the dat javascript API. You can use the Dat API directly and build more on top with the same idea of live, hosted content. The dat-now library sets a few tricky options we need for Dat to work on now.sh (bugs we are working out).
This is dat-now
in its entirety.
var Dat = require('dat')
var opts = {
key: process.env.KEY
}
// dat will save files to /tmp, the only location now.sh supports
Dat('/tmp', opts, function (err, dat) {
if (err) throw err
dat.joinNetwork({
utp: false, // utp doesn't work on now.sh right now
upload: false // upload needs another port, now.sh can only expose one port
})
dat.serveHttp({port: 8080, footer: `Sharing via dat on now.sh.`})
})