title: Express.js How to upload files(img,audio) with Mongoose Schema
body: <p>After some advices from  vernak2539 where to look after solution. My example of using express.js with formidable and mongoose look like this</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var post = require('./models');
  var formidable = require('formidable');
  var util = require('util');
  var fs   = require('fs-extra');
  
  
  router.post('/upload', function (req, res){
  
      var form = new formidable.IncomingForm();
      form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(util.inspect({fields: fields, files: files}));
  
      new post({title:fields.title, content:fields.content,
      image:files.image.name}).save(function (e, result) {
          console.log('new post saved', result)
        });
     });
  
      form.on('end', function(fields, files) {
      var temp_path = this.openedFiles[0].path;
      var file_name = this.openedFiles[0].name;
      var new_location = 'uploads/';
      fs.copy(temp_path, new_location + file_name, function(err) {
          if (err) {
              console.error(err);
          } else {
              console.log("success!")
          }
        });
     });
   });
  </code></pre>
  
  <p>So basically to use files, I save the name of the file in image field and set the static path to directory with updated files, so then it can be used as src to img.</p>