Build command line tools with nodes and plants

  • Home / Blog / Build command line…

Build command line tools with nodes and plants

Command line tools are one of the most popular applications we have today. We use command line tools every day, and they range from gut, NPM or yarn. Command line tools are very fast and useful for automating applications and workflows.

In this post we will develop a command line tool for our database with Node.js and Fauna. In addition, we will create random quotes applications using Node.js, and add permissions and keywords to our app.

Terms

To take full advantage of this tutorial, make sure you have the following installed on your local development environment:

  • Node. JS version> = 16.xx installed.
  • Access a package manager such as Npm or Yarn.
  • Access to the Fauna Dashboard.

Getting started with plants

Register a new account using email credentials or a GitHub account. You can register a new account here. Once you create a new account or sign in, you’ll be greeted with a dashboard screen.

Creating a new animal example

To create a new database example using Fauna Services, you need to follow a few simple steps. On the Dashboard screen, press the New Database button:

Next, enter and save the database name. Once the database instance is set up, you will be able to access the key. Get ready Use the access keys to allow permissions from a single page application and to connect to a database. To create your access key, go to the side menu, and go to the Security tab and click the New key button.

Creating a collection

Navigate to your dashboard, click the Collection tab from the side menu, click New Collection, click the button, enter your desired name for the new collection and save.

Indexing

To complete setup, create an index for our application. Indexes are important because search documents are compiled using the index in Fauna, combining user input with the tour field. Create an index by going to the Index tab of our Fiona Dashboard.

Now, we node. Ready to build your Note command line application using JS and your database.

Node. Launch the JS app and install the dependency

This section will launch the Node.js application and install the dependencies that we need to use the NPM package. We are also going to create an easy quote request from this link.

getting started

To get started, let’s create a folder for your application inside the project folder on your terminal using the code block below:

mkdir quotes_cli
cd quotes_cli
touch quotes_app
npm init -y

In the code block above, we created a new directory, went to the directory, and created a new file called quotes_app, and started and ended the Npm dependency. Next, add a package to make requests to the query server using Axis.

npm i axios

Add a package to color 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 DatNew package using Kot Block:

npm i dotenv

Creating a quotes app

In our quotes_app file, let’s add a 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 Axis, Chalk, and Datney. We added URLs using our database, our Fiona database, and axes, we requested GET on the URLs and added headers so we could get our response in JSS. Enable

To log a reference, we use a reference to JavaScript on our console and promises to log the author and add a lacquer method to catch 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 the result like the picture below

To draw conclusions

In this article, we learned more about plants and the Node.js command line tools. You can extend the application to be able to include date reminders in real time.

Here is a list of some resources you might like after reading this post:

Write a Comment

Your email address will not be published. Required fields are marked *

x