title: Node.js: File Upload API and JSON return
body: <p>I'm totally new to node.js, so I'm trying to find a way to create an image-file upload API, which returns a json after the process is finished. 
  I'm using the Watson Developer Cloud (Visual Recognition), which returns a JSON after finishing the processing task.  </p>
  
  <p>I hope you have tips &amp; ideas on how to get this project done. I thought about using the express library? </p>
  
  <p><strong>This is my code, which processes a local image right now and logs the JSON result to the console. I want to be able to upload an image via api and return the JSON, after the process is done.</strong> </p>
  
  <p>Thanks a lot! </p>
  
  <p>Code to process Image: </p>
  
  <pre><code>var watson = require('watson-developer-cloud') 
  var fs = require('fs')  
  
  //initialisng the service
  var visual_recognition = watson.visual_recognition({ 
      api_key : '&lt;Enter API Key here&gt;',  
      version: 'v3',
      version_date: '2016-05-20' 
  });   
  
  
  var params = { 
      images_file: fs.createReadStream('./resources/image.jpg')
  };  
  
  visual_recognition.classify(params, function(err, res){ 
      if(err) 
          console.log(err); 
      else 
          console.log(JSON.stringify(res, null, 2)); 
  });   
  </code></pre>
  
  <p>First Try for the upload Server (Thanks to @Eduard for the tip): </p>
  
  <pre><code>var express = require('express')
  var multer  = require('multer')
  var upload = multer({ dest: 'uploads/' }) 
  
  
  var app = express()
  
  app.post('/upload', upload.single('avatar'), function (req, res, next) {
      if(err){
          console.log("Error uploading file"); 
      }   
      console.log(req.file);  
      console.log(req.body); 
  
      res.status(204).end();
      console.log("Upload success"); 
  }) 
  
  app.listen(3000, function () {
    console.log('Upload Server listening on port 3000');
  });
  </code></pre>
  
  <p>Unfortunately this returns a 'ReferenceError: err is not defined[..]', while uploading an image with this simple Python Script: </p>
  
  <pre><code>import requests
  url='http://localhost:3000/upload'
  imageURL = 'ImageURL'
  
  with open(imageURL, 'rb') as image:
      filename = image.name
      files = {'avatar': (image)}
      r = requests.request(method="POST", url=url, files=files)
      print(r.text);
      print(r.status_code)
  </code></pre>
  
  <hr>
  
  <p>Sidenote: 
  Why do I want to use a Node.js Server? 
  Unfortunately the Watson-Developer-Cloud Python SDK is not supported on my hardware (a robot) and using the API endpoint with a direct upload from python causes trouble due to the old python Version on the hardware (SNI Problems) </p>