How To Browse Stack Overflow From Terminal

0 87

A while ago, we have written about SoCLI, a python script to search and browse Stack Overflow website from command line. Today, we will discuss about a similar tool named “how2”. It is a command line utility to browse Stack Overflow from Terminal. You can query in the plain English as the way you do in Google search and it uses Google and Stackoverflow APIs to search for the given queries. It is free and open source utility written using NodeJS.

Browse Stack Overflow From Terminal Using how2

Since how2 is a NodeJS package, we can install it using Npm package manager. If you haven’t installed Npm and NodeJS already, refer the following guide.

After installing Npm and NodeJS, run the following command to install how2 utility.

$ npm install -g how2

Now let us see how to browse Stack Overflow uisng this program. The typical usage to search through Stack Overflow site using “how2” utility is:

$ how2 

For example, I am going to search for how to create tgz archive.

$ how2 create archive tgz

Oops! I get the following error.

Transport.prototype.__proto__ = EventEmitter.prototype;
TypeError: Cannot read property 'prototype' of undefined
at Object. (/home/sk/.nvm/versions/node/v9.11.1/lib/node_modules/how2/node_modules/devnull/transports/transport.js:59:46)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
at Function.Module._load (internal/modules/cjs/loader.js:498:3)
at Module.require (internal/modules/cjs/loader.js:598:17)
at require (internal/modules/cjs/helpers.js:11:18)
at Object. (/home/sk/.nvm/versions/node/v9.11.1/lib/node_modules/how2/node_modules/devnull/transports/stream.js:8:17)
at Module._compile (internal/modules/cjs/loader.js:654:30)

I may be a bug. I hope it gets fixed in the future versions. However, I find a workaround posted here.

To fix this error temporarily, you need to edit the transport.js file using command:

$ vi /home/sk/.nvm/versions/node/v9.11.1/lib/node_modules/how2/node_modules/devnull/transports/transport.js

The actual path of this file will be displayed in your error output. Replace the above file path with your own. Then find the following line:

var EventEmitter = process.EventEmitter;

and replace it with following line:

var EventEmitter = require('events');

Press ESC and type :wq to save and quit the file.

Now search again the query.

$ how2 create archive tgz

Here is the sample output from my Ubuntu system.

How To Browse Stack Overflow From Terminal

If the answer you’re looking for is not displayed in the above output, press SPACE BAR key to start the interactive search where you can go through all suggested questions and answers from the Stack Overflow site.

How To Browse Stack Overflow From Terminal

Use UP/DOWN arrows to move between the results. Once you got the right answer/question, hit SPACE BAR or ENTER key to open it in the Terminal.

How To Browse Stack Overflow From Terminal

To go back and exit, press ESC.

Search answers for specific language

If you don’t specify a language it defaults to Bash unix command line and give you immediately the most likely answer as above. You can also narrow the results to a specific language, for example perl, python, c, Java etc.

For instance, to search for queries related to “Python” language only using -l flag as shown below.

$ how2 -l python linked list

How To Browse Stack Overflow From Terminal

To get a quick help, type:

$ how2 -h


The how2 utility is a basic command line program to quickly search for questions and answers from Stack Overflow without leaving your Terminal and it does this job pretty well. However, it is just CLI browser for Stack overflow. For some advanced features such as searching most voted questions, searching queries using multiple tags, colored interface, submitting a new question and viewing questions stats etc., SoCLI is good to go.

And, that’s all for now. Hope this was useful. I will be soon here with another useful guide. Until then, stay tuned with OSTechNix!



Source : Visit

You might also like More from author

Leave A Reply

Your email address will not be published.