Tuesday 11 April 2017

Pass user input from inquirer to google api

I'm trying to build a CLI app in node.js that takes a book name from the user and returns information about that book using the google books api. I am using inquirer to collect user input. How can i retrieve the value entered by the user and pass it as a query argument to the google books api.

function getBookName(callback) {
    var bookName = [
   {
      name: 'book_name',
      type: 'input',
      message: 'Enter the name of the book you want search for:',
      validate: function( value ) {
        if (value.length) {
        return true;
        } else {
          return 'Please enter a value ';
        }
      }
    }
  ];
    inquirer.prompt(bookName).then(callback);
 }

getBookName(function(){
  console.log(arguments);
});

//Write the output to to file called output.htm. I'm passing 'book_name' as query argument.
  request("https://www.googleapis.com/books/v1/volumes?q='book_name'&callback=handleResponse").pipe(fs.createWriteStream("output.htm"));



via ss_millionaire

No comments:

Post a Comment