Graphs on Tap
Tags: neo4j, cli, node
Published: 2020-11-12 14:02:27

[Neo4j Relate](https://github.com/neo4j-devtools/relate)  delivers graphs on tap. From the CLI, from your app, or from a local server, you can provision Neo4j databases whenever you'd like to enjoy the clean, refreshing goodness of graphs.

# Extracted from Neo4j Desktop

> The best frameworks are in my opinion extracted, not envisioned.
> -- [David Heinemeier Hansson](https://dhh.dk/posts/6-why-theres-no-rails-inc)

Neo4j Desktop is a native application which packages up everything you need for working with the Neo4j DBMS.

- Neo4j DBMS download and management
- Neo4j connection management 
- tools like [Neo4j Browser](https://neo4j.com/developer/neo4j-browser/), [Neo4j Bloom](https://neo4j.com/developer/neo4j-bloom/) and [Neo4j ETL](https://neo4j.com/labs/etl-tool/)

Internally, there is a GraphQL API through which tools may discover available databases, provision new ones and negotiate authentication.

Neo4j Desktop is extensible. New tools can be added, and you can write your own. But it feels like a walled garden.  Peering over the hedge, wouldn't it be nice to easily manage Neo4j from the command line, or from VS Code, or even from within your app? 

Neo4j Relate extracts the core operational library of Neo4j Desktop then packages that into a CLI tool, a web server, or a generic Electron app. Let's take the CLI for a spin.

![CLI, App, Server to Neo4j Relate](https://dev-to-uploads.s3.amazonaws.com/i/s5vxa4wcgnsxbiiy90yw.png)

# Neo4j at your command

> Now witness the firepower of this fully armed and operational ~~battle station~~ CLI
> -- [The Emperor](https://www.imdb.com/title/tt0086190/characters/nm0001519#quotes)

The [`@relate/cli`](https://www.npmjs.com/package/@relate/cli) package installs the `relate` command line tool. There [is a PR](https://github.com/neo4j-devtools/relate/pull/209) which will make the CLI available without requiring node.js. 

For now, try:

```Shell
npm install -g @relate/cli
```

Set up a provisioning environment:

```Shell
relate env:init --name=graphs-on-tap --type=LOCAL
```

Accept the default settings when prompted. You'll need to provide this semi-secret access code `r31473`:
```Shell
Enter the access code you received from applying at https://neo4j.relate.by/invite:r31473
✔ Do you need to enable authentication? (y/N) · false
✔ Do you need to restrict access to the GraphQL API methods? (y/N) · false
✔ Are HTTP consumers required to have an API key? (y/N) · false
Creating environment... done
```
The authentication mentioned above is for the GraphQL API, which we'll explore in a later post.

Now install a Neo4j DBMS named "hello" into the provisioning environment named "graphs-on-tap". If you drop `4.1.3` from the end, you can pick which version to install:

```Shell
relate dbms:install -e graphs-on-tap --name hello 4.1.3
```

`Enter new passphrase:` will set the password for the admin user named "neo4j":

```Shell
✔ Enter new passphrase · 
DOWNLOAD PROGRESS [████████████████████████████████████████] 100%
extracting neo4j... done
[b92ada41] hello
```

Finally, start the DBMS named "hello" within the "graphs-on-tap" environment:

```Shell
relate dbms:start -e graphs-on-tap hello
```

Neo4j DBMS should start up, then you'll be able to browse to http://localhost:7474 to use Neo4j Browser. Use the admin user named `neo4j` and the password you set above.

Convenient, right?

Try `relate --help` to see the other available commands and options. For instance, `relate env:use` to set the "current" environment, saving you a little typing.

## Next steps

Neo4j Relate is in alpha, evolving quickly with more capabilities and integrations. Stay tuned and reach out to me with any ideas or questions.  

In later posts, I'll explore:

- e2e testing using `relate` to do setup & teardown 
- hosting Browser, Bloom and other tools _without_ needing Neo4j Desktop
- spinning up a server to provision DBMSes on demand
- writing [nest.js](https://nestjs.com) modules to use `relate` as an application server

---

# Related...

{% github neo4j-devtools/relate no-readme %}
{% post adamcowley/building-a-modern-web-application-with-neo4j-and-nestjs-38ih %}