title: Why can I upload files with Formidable to folders using absolute path but not relative?
body: <p>Like so many other newbies, I'm following along "The Node Beginner Book" by Manuel Kiessling.</p>
  
  <p>We're supposed to enable image uploading through the Formidable module, constantly renaming the image to "test.png" and displaying it.</p>
  
  <p>The book uses the path <code>/tmp/test.png</code> and everything works fine. But that is not a relative path, and my images are actually saved in my tmp folder in Linux!</p>
  
  <p>I created the folder "tmp" in my project instead and tried to make the same thing happen there but I am only shown an error!</p>
  
  <pre><code>ENOENT, open './tmp/test.png'
  </code></pre>
  
  <p>The same thing happens when I try the path <code>tmp/test.png</code> but the funny part is that both these paths work when I put an actual image directly into the tmp folder and display it on my page. So there's not something wrong with semantics/syntax, or..?</p>
  
  <p>My requestHandler.js, with the important part being the upload and show functions:</p>
  
  <pre><code>var querystring = require("querystring"),
  fs = require("fs"),
  formidable = require("formidable");
  
  function start(response) {
    console.log("Request handler 'start' was called.");
  
      var body = '&lt;html&gt;' +
          '&lt;head&gt;' +
          '&lt;meta http-equiv="Content-Type" content="text/html; ' +
          'charset=UTF-8" /&gt;' +
          '&lt;/head&gt;' +
          '&lt;body&gt;' +
          '&lt;form action="/upload" enctype="multipart/form-data" ' +
          'method="post"&gt;' +
          '&lt;input type="file" name="upload" multiple="multiple"&gt;' +
          '&lt;input type="submit" value="Upload file" /&gt;' +
          '&lt;/form&gt;' +
          '&lt;/body&gt;' +
          '&lt;/html&gt;';
  
      response.writeHead(200, {"Content-Type": "text/html"});
      response.write(body);
      response.end();
  
  }
  
  function upload(response, request) {
    console.log("Request handler 'upload' was called.");
  
    var form = new formidable.IncomingForm();
    console.log("about to parse");
    form.parse(request, function(error, fields, files) {
      console.log("parsing done");
  
      fs.rename(files.upload.path, "./tmp/test.png", function(err) {
          if (err) {
              console.log("Error Flynn");
              fs.unlink("./tmp/test.png");
              fs.rename(files.upload.path, "./tmp/test.png");
          }
      });
  
      response.writeHead(200, {"Content-Type": "text/html"});
      response.write("received image:&lt;br/&gt;");
      response.write("&lt;img src='/show' /&gt;");
      response.end();
  });
  }
  
  function show(response) {
    console.log("Request handler 'show' was called.");
    fs.readFile("./tmp/test.png", "binary", function(error, file) {
      if(error) {
          response.writeHead(500, {"Content-Type": "text/plain"});
          response.write(error + "\n");
          response.end();
      }
      else {
          response.writeHead(200, {"Content-Type": "image/png"});
          response.write(file, "binary");
          response.end();
      }
    });
  }
  
  exports.start = start;
  exports.upload = upload;
  exports.show = show;
  </code></pre>
  
  <p>Worth noting is that the "Error Flynn" error message I specifically put there to troubleshoot <strong>does</strong> get called and the file I put in the folder deleted!</p>
  
  <p>Here's the log:</p>
  
  <pre><code>Request for /upload received.
  About to route a request for /upload
  Request handler 'upload' was called.
  about to parse
  parsing done
  Error Flynn
  fs: missing callback Error: ENOENT, unlink './tmp/test.png'
  fs: missing callback Error: EXDEV, rename '/tmp/upload_9bcb8afa8cd2f78ff52c294edd106965'
  Request for /show received.
  About to route a request for /show
  Request handler 'show' was called.
  </code></pre>