title: I want to upload an image to my blog with node.js
body: <p>I am creating a small blog with node.js, my blog works perfectly locally, but I would like to add images to my article, I already use bootstrap to display my input but at the node. i can not save my image can you help me please?</p>
  
  <p>I use Mongoose as an online server
  (I work under linux)</p>
  
  <p>server.js</p>
  
  <pre><code>var express = require('express'),
  swig = require('swig'),
  path = require('path'),
  mongoose = require('mongoose'),
  app = express();
  
  app.use(express.logger());
  app.use(express.bodyParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.engine('html', swig.renderFile);
  
  app.set('view engine', 'html');
  app.set('views', __dirname+'/views');
  
  mongoose.connect('mongodb://**:**@**.mlab.com:**/blog');
  var Article = mongoose.model('Article', {title: String, content: 
  String, updated: Date}); 
  
  app.get('/', function(req, res){
  
      Article.find({}).sort({updated: -1}).exec(function(err, articles){
          if(err){throw err;}
  
          data = {title: 'Mon super blog', articles: articles};
          res.render('index', data);
      })
   });
  
  app.get('/article/:id', function(req, res){
      var article = Article.findById(req.params.id, function(err, 
  article){
          if(err){throw err}
              var data = {article: article, title: article.title};
          res.render('article', data);
      });
   });
  
  
   app.post('/update/:id', function(req, res){
      Article.update({ _id : req.params.id}, {
          title: req.body.titre, content: req.body.contenu, updated: new 
   Date()
      },
      function(err){
          if(err){throw err;}
          res.redirect('/');
      });
  });
  
  app.get('/edit/:id', function(req, res){
      var article = Article.findById(req.params.id, function(err, 
  article){
          if(err){throw err}
          var data = {article: article, title: 'Modifier ' 
   +article.title};
          res.render('edit', data);
      })
  })
  
  
  app.get('/destroy/:id', function(req, res){
      Article.remove({ _id : req.params.id}, function(err){
          if(err){throw err;}
          res.redirect('/');
      });
  });
  
  app.get('/create', function(req, res){
      var data = {title: 'Ajouter un article'};
      res.render('create', data);
  });
  
  app.post('/store', function(req, res){
      var article = new Article({
          title: req.body.titre,
          content: req.body.contenu,
          updated: new Date()
      });
  
      article.save(function(err, article){
          if(err){throw err;}
          res.render('created');
      });
  });
  
  app.listen(3000);
  console.log('App running http://localhost:3000');
  </code></pre>
  
  <p>create.html</p>
  
  <pre><code>{% extends 'layout.html' %}
  
  {% block content %}
  
  &lt;form role="form" action="/store" method="post"&gt;
  
  &lt;div class="form-group"&gt;
  &lt;label for="titre"&gt;Titre&lt;/label&gt;
  &lt;input type="text" name="titre" class="form-control" 
  placeholder="titre de l'article" required&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;label for="titre"&gt;Titre&lt;/label&gt;
      &lt;label for="contenu"&gt;Contenu de l'article&lt;/label&gt;
      &lt;textarea name="contenu" class="form-control" placeholder="Contenu 
  de l'article" rows="3" required&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  
  &lt;form&gt;
      &lt;div class="form-group"&gt;
          &lt;label&gt;Telecharger une image&lt;/label&gt;
          &lt;input type="file" class="form-control-file" name="img"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;button type="submit" class="btn btn-default"&gt;Ajouter &lt;/button&gt;
  
  &lt;/form&gt;
  
  
  {% endblock %}
  </code></pre>
  
  <p>article.html</p>
  
  <pre><code>{% extends 'layout.html' %}
  
  {% block content %}
  
  &lt;span class="pull-right"&gt;&lt;a class="btn btn-danger remove" 
  href="/destroy/{{article.id}}"&gt;Le bouton magique&lt;/a&gt;&lt;/span&gt;
  
  &lt;h1&gt;{{article.title}}&lt;/h1&gt;
  
  
  &lt;p&gt;{{article.content}}&lt;/p&gt;
  
  &lt;span class="date"&gt;
  Mis à jour {{article.updated.getDate()}} / 
  {{article.updated.getMonth() +1}} / {{article.updated.getFullYear()}}
  &lt;/span&gt;
  
  &lt;div class="pull-right"&gt;
  &lt;a href="/edit/{{article.id}}" class="btn btn-default"&gt;Modifier&lt;/a&gt;
  &lt;/div&gt;
  
  {% endblock %}
  </code></pre>