title: TypeError: callback is not a function in nodejs
body: <p>I am trying learn nodejs and stumble upon this error </p>
  
  <p><em>TypeError: callback is not a function</em></p>
  
  <p>when I am trying to call the server using this command.</p>
  
  <p><em>curl <a href="http://localhost:8090/albums.json" rel="noreferrer">http://localhost:8090/albums.json</a></em></p>
  
  <p>and here is the code for my server.js</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var http = require('http'),
    fs = require('fs');
  
  function load_album(album_name, callback) {
    fs.readdir("albums/", +album_name, (err, files) =&gt; {
      if (err) {
        if (err.code == "ENOENT") {
          callback(make_error("no_such_album", "That album doesn't exist"));
        } else {
          callback(make_error("can't load album", "The server is broken"));
        }
      } else {
        //callback(null, files);
        var only_files = [];
        var path = 'albums/${album_name}/';
  
        var iterator = (index) =&gt; {
          if (index == files.length) {
            var obj = {
              short_name: album_name,
              photos: only_files
            };
            callback(null, obj);
            return;
          }
  
          fs.stat(path + files[index], (err, stats) =&gt; {
            if (!err &amp;&amp; stats.isFile()) {
              only_files.push(files[index]);
            }
            iterator(index + 1);
          });
        };
        iterator(0);
      }
    });
  }
  
  
  function handle_incoming_request(req, res) {
    console.log("incoming request: " + req.method + " " + req.url);
  
    if (req.url == '/albums.json') {
      load_album((err, albums) =&gt; {
        if (err) {
          res.writeHead(500, {
            "Content-Type": "application/json "
          });
          res.end(JSON.stringify({
            code: "cant_load_albums",
            message: err.message
          }));
        } else {
          var output = {
            error: null,
            data: {
              albums: albums
            }
          };
          res.writeHead(200, {
            "Content-Type": "application/json"
          });
          res.end(JSON.stringify(output) + "\n");
        }
      });
    } else if (req.url.substr(0, 7) == '/albums' &amp;&amp; req.url.substr(req.url.length - 5) == '.json') {
      //user is requesting contents of album
      load_album(req.url.substr(7, req.url.length - 12), (err, photos) =&gt; {
        if (err) {
          res.writeHead(500, {
            "Content-type": "application/json"
          });
          res.end(JSON.stringify(err));
        } else {
          var output = {
            error: null,
            data: {
              photos: photos
            }
          };
          res.writeHead(200, {
            "Content-Type": application / json
          });
          res.end(JSON.stringify(output) + "\n");
        }
      });
    } else {
      res.writeHead(404, {
        "Content-type": "application/json"
      });
      res.end(JSON.stringify({
        code: "no_such_page",
        message: "No such page"
      }));
    }
  }
  var s = http.createServer(handle_incoming_request);
  s.listen(8090);</code></pre>
  </div>
  </div>
  </p>
  
  <p>can you tell me what's wrong with my code that I got an error telling me callback isn't a function?</p>
  
  <p>thanks though</p>
  
  <p>for more formatted code then you can go here <a href="https://jsfiddle.net/02dbx6m9/" rel="noreferrer">https://jsfiddle.net/02dbx6m9/</a></p>