How can i upload images with NodeJS and express?
<p>I want to upload images to a specified folder and save the path in the model with <strong><em>mongoose</em></strong> and <strong><em>multer</em></strong> modules. </p>

<p>I added <code>ImageSavePath.array(req.body.image[5]);</code> How can i have the filepath as string inside <code>ProjectImagePath</code>? Here comes my files:</p>

<p><strong>controller/projectController.js</strong></p>

<pre><code>var mongoose = require('mongoose');
var passport = require('passport');
var Project = require('../models/projects');
var multer = require('multer');
var ImageSavePath = multer({
  dest: '../userFiles/projectImage',
  rename: function (fieldname, filename) {
    return filename.replace(/\W+/g, '-').toLowerCase() + Date.now();
  });
}
module.exports = {

    plain : function (req, res) {
      //Datos cocinados con la respuesta...
      if(!req.user){
        res.redirect('/user/login');
      }
      res.render('project/resume', {
        // resume page view parameters
        title : "proyectos",
        user : req.user,
      });
    },
    create : function (req, res) {
      //Datos cocinados con la respuesta...
      if(!req.user){
        res.redirect('/user/login');
      }
      res.render('project/create', {
        // resume page view parameters
        title : "Crear proyecto",
        user : req.user,
        projectName: "Nombre del proyecto",
        image: "Subir imágen",
        plane: "Subir plano en formato PDF",
        details: "Detalles, información sobre el proyecto.",
        ammount: "¿Cual es el coste de esto?",
        location: "Localización",

      });
    },
    saveProject : function (req, res){
      ImageSavePath.array(req.body.image[5]);
      var saveProject = new Project({
        ProjectOwner : req.user._id,
        ProjectName : req.body.projectName,
        ProjectDetails : req.body.projectDetails
        ProjectImagePath : ImageSavePath,
        ProjectPdfPath : req.body.plane,
        ProjectAmount : req.body.ammount,
        ProjectLocation : req.body.localize,
      });
      saveProject.save(function(err){
        if(err){
          res.render('project/create', {
            title: "La información no es válida, volver a introducir los datos",
          });
        }
      });
    },
  }
</code></pre>

<p><strong>models/projects.js</strong></p>

<pre><code>var mongoose = require('mongoose');
var Schema = mongoose.Schema;


var project = new Schema({
  ProjectOwner: String,
  ProjectName: String,
  ProjectDetails: String,
  ProjectImagePath: [String],
  ProjectPdfPath: String,
  ProjectLocation: Number,
  ProjectAmount: String,
  });

module.exports = mongoose.model('project', project);
</code></pre>

<p><strong>routes/projects.js</strong></p>

<pre><code>var express = require('express');
var controller = require('../controllers/projectController');
var passport = require('passport');
var router = express.Router();


router.get('/', controller.plain);
router.get('/create', controller.create);
router.post('/create', controller.saveProject);
//router.get('/edit', controller.create);
//router.post('/create', controller.save);
//router.get('/delete', controller.delete);
module.exports = router;
</code></pre>

<p><strong>app.js</strong></p>

<pre><code>var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var session = require('express-session');

var index = require('./routes/index');
var users = require('./routes/users');
var projects = require('./routes/projects');

var app = express();
// para devolver estado por consola.
app.use(morgan('combined'));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
var Account = require('./models/accounts');
passport.use(new LocalStrategy(Account.authenticate()));
passport.serializeUser(Account.serializeUser());
passport.deserializeUser(Account.deserializeUser());

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

app.use(express.static(path.join(__dirname, 'public')));

app.use(require('express-session')({
    secret: 'topSecret',
    resave: true,
    saveUninitialized: true,
    cookie: { maxAge : 3600000 } //1 Hour
}));

app.use(passport.initialize());
app.use(passport.session());
//Rutas express
app.use('/', index);
app.use('/user', users);
app.use('/project', projects);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});

mongoose.connect('mongodb://localhost/database');

module.exports = app;
</code></pre>

<p><strong>project/create.jade</strong></p>

<pre><code>extends ../includes/layout

block content
  div(class="wrap")
    include ../includes/header
    div(class="column-group vertical-space")
      div(class="all-50 push-center")
        div(class="all-100")
          h1 #{title}
        div(class="all-100")
        form(role="form" method="post" action="create" enctype="multipart/form-data")
          p #{projectName}
          input(type="text" name="projectName" required)
          p #{image}
          input(type="file" name="image")
          p #{plane}
          input(type="file" name="plane")
          p #{details}
          input(type="text" name="details")
          p #{ammount}
          input(type="number" name="ammount")
          p #{location}
          input(type="text" name="localize")
          button(type="submit") Enviar
    div(class="push")
  include ../includes/footer
</code></pre>