title: How to remove a directory if it exists and is not empty?
body: <p>I'm trying to remove node_modules directory if it exists and is not empty</p>
  <pre class="lang-js prettyprint-override"><code>var fs = require('fs'),
      path = require('path'),
      child_process = require('child_process'),
      cmd;
  
  module.exports = function(){
      var modulesPath = '../modules';
  
      fs.readdirSync(modulesPath)
          .forEach(function(dir) {
              var location = path.join(dir, 'node_modules');
              if (fs.existsSync(location)){
                  fs.rmdir(location);
              }
          });
  };
  </code></pre>
  <p>However, <code>fs.rmdir</code> command unfortunately removes directory <em>only if there are no files there</em>.</p>
  <p>NodeJS doesn’t have an easy way to force the removal</p>