Node JS – Manipulation with files and JSON

JSON is somehow powerful. With Node JS and JSON you may build almost anything you can think of (if you have unlimited time and coffee/beer).

json-mini-logoHow about building a small console application with the following options:

Yesterday, I started to build a console application, similar to this one, but still not the same and in Java Script. The current one is running over a JSON file, making some editions with it. The program has the following features:

add enables you to add a new entry to the JSON

get gives information for the entry on a specific id

remove removes entry from the JSO

update updates entry at JSON

search searches in JSON and returns the data (the get searches only per IDs, this is more general)

load loads a new JSON variable from a file

nice prints the JSON file in a beautiful table, adjustable by the size of the variables. I have used hardcoding in the function  promptNiceCommand();, which I am not proud of, but the result was quite satisfactory.

save saves the JSON variable into a file

quit quits the application


Indeed, a fully functioning application. Loading DB, editing it, searching it, displaying it and saving the results. Well, the interface is a little chabby indeed, but it works:


Here comes the code. Make sure you have “file.json” in the same dir, containing something like this to have the application running smoothly:


Here comes the code, enjoy it responsibly :

That’s all folks! The code in GitHub is here. Finally:



Probably the answer is “NO”, but I like the picture.

Tagged with: , , , , , , , ,