Skip to main content

Command Palette

Search for a command to run...

How I Built a CLI for Dictionary - ReactJs

Updated
3 min read
How I Built a CLI for Dictionary - ReactJs
S

I’m a Software Developer with a strong foundation in building scalable, accessible, and inclusive products across both early-stage startups and enterprise environments. My experience spans backend-heavy systems, real-time data pipelines, and internal tooling that drives measurable impact.

I currently work at WorkIndia as a Software Development Engineer, where I help design and build robust backend systems, real-time data pipelines, and automation tools that power one of India’s largest job platforms. Previously, I interned at Microsoft and Raven (YC S22), where I contributed to building end-to-end, production-ready features that significantly improved product performance and operational efficiency.

Outside of work, I’m building Evolv, a fitness app designed to go beyond tracking, helping users build intentional workout rituals backed by meaningful insights. It’s been an exciting journey bringing product thinking and engineering together to solve a deeply personal problem.

🧠 Leadership & Mentorship Mentoring junior developers and interns, helping them grow technically and align with real-world engineering best practices.

💡 Community & Communication Beyond code, I’m a people-first engineer. I’ve led developer communities, such as the Google Developer Student Club at university, scaling it to over 2,000 members. I’ve spoken at tech events and enjoy sharing ideas, whether through talks or writing. I also maintain a blog where I explore both the technical and human side of software development.

🛠️ Technical Interests Backend systems • Event-driven architecture • Real-time data pipelines • Internal developer tools • Automation • Platform thinking

Yeah, you heard that right recently I built a CLI for a dictionary in reactjs using an awesome library React-Ink and guess what? this is an open-source project if you want to contribute to good karma find the repo link here.

What are we going to build?

Well, we will explore how ink works and I will take you through the process of me building a CLI dictionary out of it. I will be using the free dictionary API for this to fetch our data for a particular query.

What is React-Ink?

Ink provides the same component-based UI-building experience that Reacts offers in the browser, but for command-line apps. It uses Yoga to build Flexbox layouts in the terminal, so most CSS-like props are also available in Ink. If you are already familiar with React, you already know Ink. Since Ink is a React renderer, it means that all features of React are supported.

Creating Ink project

If you have been working on react for quite some time then this step would be similar to you -

1 - Let's first create an empty directory. Let's name the project "Lexical" since lexical is another name for a dictionary.

mkdir lexical-cli && cd lexical-cli

2 - Now you run the create-ink-app command, this is similar to when you create react-app.

npx create-ink-app

3 - Now initialize the folder as a git repo, I like to do this every time I work on something new it helps me keep the track of my progress. You can skip this if you want.

git init

Now the command would have generated some very basic files just like we see in react, you can ignore everything other than the source/ui.js folder.

import React, { FC } from "react";
import { Text } from "ink";

const App: FC<{ name?: string }> = ({ name = "Stranger" }) => (
    <Text>
        Hello, <Text color="green">{name}</Text>
    </Text>
);

module.exports = App;
export default App;

This is a normal App component like you see in React. A prop name is passed on to this component which is set to a default value of Stranger and a message of “Hello {name}” is rendered. Note that the Text component comes from ink. It can be used to style many aspects of the text, like the colour, background colour, etc. We will do everything in this file only.

Building the dictionary CLI

Now, to get started we would need to install the axios in our project and create a basic function to fetch our data from the API.

npm i axios

Function to send the request -

    const lexicon = word => {
        const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`;

        return axios.get(url).then(response => response.data).then((data) => {

            return data[0];

        })
    }

Let’s also create a state variable to store our dictionary data -

const [lexiconData, setlexiconData] = React.useState(null);

Now let's use the useEffect hook to call this function -

useEffect(() => {
        lexicon(word).then(data => {

            setlexiconData(data)
        })

    }, [word]);

Amazingly Awesomely Amazing!!! 🎉

Now the last step remains to display all the data, for that -

return (
            < Box >
                <Text>
                    <Text color="yellowBright">Word:</Text>{" "}
                    <Text bold color="magentaBright">
                        {lexiconData?.word.toUpperCase()}
                    </Text>
                    {"\n"}
                    <Text color="yellowBright">Definition:</Text>{" "}
                    <Text color="greenBright" bold>
                        {lexiconData?.meanings.map((meanings) => meanings.definitions[0].definition)}
                    </Text>
                    {"\n"}
                    <Text color="yellowBright">Synonym:</Text>{" "}
                    <Text color="greenBright" bold>
                        {lexiconData?.meanings.map((meanings) => meanings.synonyms[0])}
                    </Text>
                    {"\n"}
                    <Text color="yellowBright">Antonym:</Text>{" "}
                    <Text color="greenBright" bold>
                        {lexiconData?.meanings.map((meanings) => meanings.antonyms[0])}
                    </Text>
                </Text>
            </Box >
    );

Cool!! All set, Its time to test it 🧪

Running the CLI

npm run build

Now run the executable

lexical-cli --word=favour

example-img.jpg

Voilà!!! We did it!!!

Well thanks for following up with me, Hope this was helpful. For any feedback you can reach out to me here. And you can find the repo link here

More from this blog

Siddharth Khuntwal

10 posts

I am a Creator, Developer and Designer. I love making beautiful websites and teaching others how to make them by writing blogs. I bring my imagination into reality through my Art.