title: Increase speed sending static images with nodeJS
body: <p>I have a typical <strong>client/server</strong> application where i can send images to the server and i need that image on the client with diferent sizes.</p>
  
  <p>So at the moment i am using Picasso with android to load the image, and with nodeJS i am serving the images as static files, since they are saved in the folder where the static files are.</p>
  
  <p>My question is: is there a way to increase the speed sending this static files(just the images), or can i decrease the size of them using the code that i currently have for the static file?</p>
  
  <pre><code>app.use(express.static(path.join(__dirname, 'public')));
  </code></pre>
  
  <p>at the moment i receive the image from the client as <strong>base64</strong> and on the server i convert it to a bitmap like this:</p>
  
  <p>var bitmap = new Buffer(req.body.base64, 'base64');</p>
  
  <p>and store that bitmap on the public folder that i use as a static folder, i dont store the image directly on the database since that is bad practice, i just save the path and everytime i want to retrive the image i know inside the static folder where it is.</p>
  
  <p>So everytime on my client that i want to retrive a foto i just need to know what is the static path, nothing more.</p>
  
  <p>For a better understanding i leave here the code for 1 of my controllers where i save the photo.</p>
  
  <p><strong>controller</strong></p>
  
  <pre><code>sendPicture: function (req, res, next) {
          var plant = null
          if (req.params.id != 0) {
              plant = req.params.id;
          }
          var bitmap = new Buffer(req.body.base64, 'base64');
          var lat = req.body.lat;
          var lon = req.body.lon;
          var alt = req.body.alt;
          var date = req.body.date;
          var flowerName;
          var pathId = shortid.generate();
          var userId = req.userId;
  
          if (plant != null) {
              Plant.findOne({
                  where: { id: req.params.id }
              }).then(function (plant) {
                  if (!plant) {
                      return 'not found';
                  }
                  flowerName = plant.specie;
              }).then(function () {
  
                  var pathToSave = __dirname + "/../public/images/" + flowerName + "/" + pathId + req.params.id + "-" + userId + ".jpg";
                  var path = "images/" + flowerName + "/" + pathId + req.params.id + "-" + userId + ".jpg"
  
  
                  fsPath.writeFile(pathToSave, bitmap, function (err) {
                      if (err) {
                          console.log(err.stack);
                          return err;
                      }
                      Foto.create({
                          image: path,
                          userId: userId,
                          plantId: req.params.id,
                          lat: req.body.lat,
                          lon: req.body.lon,
                          alt: req.body.alt,
                          date: date,
                      }).then(function () {
                          return res.status(200).json({ message: "foto created" });
                      }).catch(function (err) {
                          console.log(err.stack);
                      })
  
                  });
              });
          }
  </code></pre>