Recently, I got experience working with Command Line Interface tools and I wanted to build one for myself and for the codeforces community! Many times, during a codeforces contest, I get frustrated whenever I have to recompile my code and test it with the sample test cases. Of course, I could have used third party IDE extensions or write a shell script that does everything for me but where’s the fun in that?

My intial goal was to develop a package that automatically parses i/o from codeforces and creates a file for me. Once, I am done coding I should be able to compile, run and test my solution with a single command. Codeforces contests are short in length and every minute counts. So, I preferred convention over configuration. The module assumes some basic conventions and gets the code running with two simple commands.

How do I get it?

$ npm install -g nodeforces

Where do I start?

$ nodeforces init 811B.cpp

Here, instead of explicity passing the url using -u, I chose to directly ask the problem name and the extension. It has two advantages

  • We can get a sensible filename
  • The extension .cpp would help us compile the code using g++. Again convention over configuration

The above command would produce an output that looks something like

✔ File Created at /home/krishna/811B/811B.cpp. Get ready to start coding

It assumes that problem information should be stored in the default home directory.

Alright, I think I have my solution ready. How do I test it?

$ nodeforces test 811B.cpp

And thats it! It automatically compiles and runs your code and shows the test outputs.

✔ Reporting Test Results
  ***Tests for 811B**
    ✓ Case: 1
    ✓ Case: 2

  2 passing (10ms)

In this way by having some sensible assumptions I was able to cut down complexity to two simple commands. However, this way of hardcoding everything is also not completely recommended. There should be a way to change and configure most of the important assumptions we make. For instance, some codeforces users might have seperate directories where they organize their contest solutions. Some users might require compiling with some debug flags eg: -DDEBUG in C++.

It made sense to add the option of config file that overrides the default assumptions. The config file must reside in the home directory.

What is the structure of this config file?

It’s a simple .cfrc json that looks like

  "src": {
    "dir": "/home/user/Documents"

  "compiler": {
    "options": ["-DDEBUG"]

So, having a configurable module with sensible defaults will be useful for advanced audience and also wont scare away any newbies.

Hmm.. looks alright, what else can it do?

Currently the module supports javac and g++. I am thinking of adding more features and ideas are welcome!

  • Neatly print debug lines and do not compare them with output. Can be done by adding a prefix (say ~) to every debug line
  • Timeouts and memory constraints on the running process.
  • Any compiler or scripting language support. Make the compile and run logic as generic as possible
  • Add submit command that submits the tested solution to the codeforces judge.

The source code is hosted on GitHub.

Try it out and give your suggestions and recommendations!