title: Using Node.JS to Issue a Command from a Text File
body: <p>For a class assignment, I am required to create a Siri like program that takes a command and an argument and returns some data from an API, or in one particular case, reads from a text file and executes the command in that file to get data on a particular song.  I understand how to read the files using the FS module, but I'm not understanding how to get it to actually use what is returned to make it a command and execute (what is essentially myPlayList(I Want It That Way).  Below is the code so far, split into Select Cases and Functions as well as what is in the text file. This is my first post and figured seeing the whole code would better give context as to what is going on.</p>
  <pre><code>var keys = require(&quot;./keys.js&quot;) 
  var twitter = require(&quot;twitter&quot;);
  var omdb = require(&quot;request&quot;);
  var spotify = require(&quot;spotify&quot;);
  var fs = require(&quot;fs&quot;);
  
  var liriCommand = process.argv[2];
  var searchTitle = process.argv[3];
  
  var twitterKeys = keys.twitterKeys;
  
  var twitterUser = new twitter({
      consumer_key: twitterKeys.consumer_key,
      consumer_secret: twitterKeys.consumer_secret,
      access_token_key: twitterKeys.access_token_key,
      access_token_secret: twitterKeys.access_token_secret
  });
  //console.log(twitterUser); okay keys working
  
  //Switch cases to call function based on liriCommand entered.
  switch(liriCommand) {
      case &quot;my-tweets&quot;:
      myTweets();
      break;
  
      case &quot;spotify-this-song&quot;:
      myPlayList();
      break;
  
      case &quot;movie-this&quot;:
      myMovie();
      break;
  
      case &quot;do-what-it-says&quot;:
      randomPick();
      break;
  }
  
  //Function for pulling in last 20 tweets
  
  function myTweets(){
      twitterUser.get('search/tweets', {q: 'burgeoningbaker', count: 20}, function(error, tweet, response) {
          if(error){
              console.log(error);
          }else{
              console.log(tweet);
          }
      });
  };
  
  //Function for pulling in artist, song name, link to song and album with song via Spotify
  function myPlayList(){
      if (!searchTitle){
          searchTitle = 'The Sign';
      }
  
      spotify.search({type: 'track', query: searchTitle}, function(err, data){
          if (err){
              console.log('Error occurred: ' + err);
              return;
          }
          //Handle Data
          var albumTrack = data.tracks.items;
  
          for (i=0; i &lt; albumTrack.length; i++){
          console.log(&quot;Artist: &quot; + albumTrack[i].artists[i].name);
          console.log(&quot;Album Title: &quot; + albumTrack[i].album.name);
          console.log(&quot;Spotify Link: &quot; + albumTrack[i].preview_url);
          console.log(&quot;Track Title: &quot; + albumTrack[i].name);
          // } else if (!data &amp;&amp; !err){
          // myPlaylist('The Sign');
          }
      };
      
  };
  
  //Function for using request to get OMDB movie information from movie object
  // Move Title, Year of release, Rating, Country, Language, Plot, Actors, Rotten Tomato Rating, URL
  
  function myMovie(){};
  
  // Function to fire off if typed do what it says
  
  function randomPick(){
      fs.readFile(&quot;random.txt&quot;, &quot;UTF-8&quot;, function(error, data){
          if (error){
              console.log(error);
          }
              console.log(data);
  
      });
  };
  </code></pre>
  <p>This is the text file contents</p>
  <p>spotify-this-song, &quot;I Want It That Way&quot;</p>