Command line tools are one of the most popular applications we have today. We use command line tools every day, and they range from git, npm or yarn. Command line tools are very fast and useful for automating applications and workflows.
We will be building a command line tool with Node.js and Fauna for our database in this post. In addition, we will be creating a random quotes application using Node.js, and add permission and a keyword for our app.
Prerequisites
To take full advantage of this tutorial, make sure you have the following installed on your local development environment:
- Node.js version >= 16.x.x installed.
- Have access to one package manager such as npm or yarn.
- Access to Fauna dashboard.
Getting Started with Fauna
Register a new account using email credentials or a GitHub account. You can register a new account here. Once you have created a new account or signed in, you are going to be welcomed by the dashboard screen:

Creating a New Fauna Instance
To create a new database instance using Fauna services, you have to follow some simple steps. On the dashboard screen, press the button New Database:

Next, enter the name of the database and save. Once a database instance is set up, you are ready to access the key. Use access keys to connect authorization and a connection to the database from a single-page application. To create your access key, navigate to the side menu, and go to the Security tab and click on the New Key button.

Creating a Collection
Navigate to your dashboard, click on the Collections tab from the side menu, press the New Collection, button, input your desired name for the new collection, and save.

Creating Indexes
To complete setup, create indexes for our application. Indexes are essential because searching documents are done using indexes in Fauna by matching the user input against the tern field. Create an index by navigating to the Indexes tab of our Fauna dashboard.

Now, we are ready to build our notes command-line application using Node.js and our database.
Initializing a Node.js App and Installing Dependencies
This section will initialize a Node.js application and install the dependencies we need using the NPM package. We are also going to build a simple quotes application from this link.
Getting Started
To get started, let’s create a folder for our application inside the project folder using the code block below on our terminal:
mkdir quotes_cli
cd quotes_cli
touch quotes_app
npm init -y
In the code block above, we created a new directory, navigated into the directory, and created a new file called quotes_app, and ended by initializing the npm dependencies. Next, add a package to make requests to the quotes server using axios.
npm i axios
Add a package for coloring our texts, chalk is an NPM package that helps us add color to print on the terminal. To add chalk, use the code block below
npm i chalk
Let’s also import a dotenv package using the code block:
npm i dotenv
Building the Quotes App
In our quotes_app file, let’s add the code block below
const axios = require('axios')
const chalk = require('chalk');
const dotenv = require('dotenv');
const url = process.env.APP_URL
axios({
method: 'get',
url: url,
headers: { 'Accept': 'application/json' },
}).then(res => {
const quote = res.data.contents.quotes[0].quote
const author = res.data.contents.quotes[0].author
const log = chalk.red(`${quote} - ${author}`)
console.log(log)
}).catch(err => {
const log = chalk.red(err)
console.log(log)
})
In the code block above, we imported axios, chalk, and dotenv. We added the URL of our database, our Fauna database, and using axios, we made a GET request to the URL and added headers to enable us to get our response in json.
To log a quote, we use JavaScript promises to log the quote and its author on our console and added a catch method for catching errors.
Before we run, let’s change the permissions on our file using the code below:
chmod +x quotes_app
Next, run the application using our keyword below:
./quotes_app
We should get a result similar to the image below

Conclusion
In this article, we learned more about Fauna and Node.js command-line tools. You can extend the application to be able to add date reminders in real-time.
Here is a list of some resources that you might like after reading this post:
I know this is a sponsored post. But do you read the ads before Posting them?!?
That is one of the worst posts I’ve read. It tells you how to create an account, that’s all. It doesn’t even tell you what Fauna is and why one would want too use it. The example won’t do anything and to call it a command line tool is just a lie.
The only thing it does, is to write log messages to the console.
I know that’s not css-tricks problem ;) but the bad post is enough reason not to check out the tool. If that is the best they could come up with to promote their service, I don’t see any reason to even look at it.
Totally agree! And the grammar is terrible as well…
I must agree with Aiko.
I feel the effort is missing from it. It seems to be a paid article.
You easily can write about a more useful topic.
To sum up, it is not bad, but not very useful in a practical way.
This is not a cli tool.
You should indicate when a post is sponsored in the RSS feed as well.
From my feed reader, I thought I was going to read a tutorial. Had it shown at the beginning, like it does on the web, that it’s a sponsored post, I would’ve known to expect an ad.
We used to do that with a big bold “This post is sponsored.” callout, but I see it’s not working now. I’ll make a note to fix that.
This tutorial is not to build command line tools, it’s how to create a script to access fauna api.
It doesn’t make much sense to use dotenv in commandline tools.
You are not using Fauna’s cli tool at all here.
The title and description are incorrect
Agreed with Aiko. This is below the standards I came to expect from CSS-Tricks. I also have used Fauna and know they are better than this. I expect both parties to be more careful about ads they commission.