Trackk - My first CLI app to stay productive from terminal

Bhavy SarwaBhavy Sarwa
3 min read

Github Link for the project.

I’ve always being a fan of ToDos app and terminal, So i thought why not to combine them together? And that resulted in creation of “Trackk” a simple clean and working TODO app.

I made it using Inquirer js package. It was pretty simple. You just need to make a couple of menu(s) to get used to it.

//This is my main menu for the app
const response = await inquirer.prompt([{
            type: "list",
            name: "choice",
            message: "\n\t----- WELCOME TO THE APP ----- \t\n",
            choices: [
                "1. Add task",
                "2. View all tasks",
                "3. View completed tasks",
                "4. View todays's tasks only",
                "5. Exit"
            ]
        }]);

I started making it with intent of just basic core functionality or like a weekend fun project, but before i knew i was in greed of just one more feature- and one more and maybe a little more?

I also used chalk js package for making the UI more impressive and clean.

//A quick look into my log.js file
import chalk from "chalk";
export const log = {
    success : msg => console.log(chalk.greenBright(`${msg}`)),
    error : msg => console.log(chalk.redBright(`${msg}`)),
    message : msg => console.log(chalk.gray.italic(`${msg}`)),
    info : msg => console.log(chalk.cyan(`${msg}`)),
    bold: msg => console.log(chalk.bold(`${msg}`)),
}

I have used file storage for presistant storage. First I thought of using mongoDB but i realise there was no need of such extra layer of complexity and also i was making it for others to use as well so i thought file storage was the best option for scope of this project.

The biggest hurdel i faced in creation of the project was to access it from anywhere from the terminal like anywhere even outside users folder (in windows) , this ambition let me to the file permission error about something EPERM. I never encounterd such error before and i spent the next hour looking into the code and trying to find error than i googled it.

Basically It means the user or process attempting the operation lacks the necessary privileges to access or modify the target file or directory. Or simply I was trying to create a file in folders which were restrictive but i was trying to create there using terminal. SO How did I fixed it? I told my npm to not create file/folder just anywhere but just store everything inside a dedicated folder in my project.

// Step 1: Get your app's folder location
const __filename = fileURLToPath(import.meta.url); // file path of fileHandler.js
const __dirname = path.dirname(__filename);        // folder containing fileHandler.js

// Step 2: Make a `.data` folder if it doesn't exist
const dataDir = path.join(__dirname, '.data');
if (!fs.existsSync(dataDir)) {
    fs.mkdirSync(dataDir); // make folder once
}

// Step 3: Define safe file paths inside `.data`
const taskFilePath = path.join(dataDir, 'tasks.json');
const completedFilePath = path.join(dataDir, 'completed.json');

You can also set the priority of the tasks and the pending time and date. This feature thought me many things about the time and date in JS. One problem i faced in this part was that i was comparing the local date which is kind of invalid in JS. Than i created seprate dates, one for comparison and another, locale date for user.

    let createdAt = new Date().toISOString()
    let localDate = new Date(createdAt).toLocaleString()
    let dueISODate = new Date(response.dueLocalDate).toISOString()
    toDos.push({task: response.task, 
                done: false, 
                priority: response.priority, 
                createdAt, 
                localDate, 
                dueLocalDate: response.dueLocalDate , 
                dueISODate});
    saveTasks(toDos);
    log.success(`Task added : ${response.task}`);
//Completed tasks
const compTask = { ...task, done: true, completedAt, completedLocalDate };

You can also have option to edit the task afterwards as well as the option to mark as undone. I have made seprate list for completed tasks and pending tasks.

It was a simple project but I learned a lot about file handling, CLI UX, Node.js modules, thinking from a user perspective and error-proof coding through this project.

This project is still in devlopment. I am thinking to integerate it with Google tasks or maybe create a notification system. I’d love your feedback both on the project and post.

Let’s build better, together!

0
Subscribe to my newsletter

Read articles from Bhavy Sarwa directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Bhavy Sarwa
Bhavy Sarwa

BTech CSE Grad '27 || MERN Stack Developer || Proficient in Java,C++, JavaScript, and SQL || git and GitHub