# Johnny Five, how to use a REPL

> Learn how to use the Johnny Five REPL to control hardware live from the terminal, requiring classes and chaining commands like lcd.clear().print().

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2021-04-29 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/johnny-five-repl/

> This post is part of the Johnny Five series. [See the first post here](https://flaviocopes.com/johnny-five/).

When you run a program using Johnny Five, you can see that in the terminal, we have access to a **REPL**, a term that means Read-Evaluate-Print-Loop.

![Terminal showing Johnny Five board connection and REPL initialization with Available, Connected, and Repl Initialized messages](https://flaviocopes.com/images/johnny-five-repl/Screenshot_2020-03-26_at_15.03.46.png)

In other words, we can write commands in here.

Let's try by creating a `repl.js` file with this code:

```js
const { Board } = require("johnny-five")
const board = new Board()
```

I am going to play with the LCD circuit made in the previous lesson.

Run the program with `node repl.js`:

![Terminal showing node repl.js command execution with board connection messages and REPL prompt](https://flaviocopes.com/images/johnny-five-repl/Screenshot_2020-03-26_at_15.16.36.png)

Next, we're going to write some commands in the REPL.

Start by requiring the LCD class:

```js
const { LCD } = require("johnny-five")
```

![Terminal REPL showing LCD class being imported from johnny-five with const LCD require command](https://flaviocopes.com/images/johnny-five-repl/Screenshot_2020-03-26_at_15.17.40.png)

Then initialize an `lcd` object from it:

```js
const lcd = new LCD({ pins: [7, 8, 9, 10, 11, 12] })
```

![Terminal REPL showing LCD object initialization with pins array configuration for pins 7 through 12](https://flaviocopes.com/images/johnny-five-repl/Screenshot_2020-03-26_at_15.19.09.png)

Now write to the LCD display:

```js
lcd.print("Hello!")
```

You'll see a big message coming back:

![Terminal showing LCD object details returned after print command with board configuration and LCD properties](https://flaviocopes.com/images/johnny-five-repl/Screenshot_2020-03-26_at_15.21.09.png)

Because the command returns a reference to the LCD object. This is to let us chain commands together, like this:

```js
lcd.clear().print("Hello!")
```

If you don't run `clear()`, any new thing you write is going to be appended to the one already there.

To write to the second row, you call `cursor(1)` (the default row is `0`:

```js
lcd.clear().print("Hello from")
lcd.cursor(1, 0).print("Johnny-Five!")
```

![Physical LCD display on breadboard showing Hello from on first row and Johnny-Five! on second row](https://flaviocopes.com/images/johnny-five-repl/IMG_9080_2.jpg)
