title: Show webcam feed, capture images and save them locally in node.js?
body: <p>I am trying to build a facial recognition module for using it in my project. This module will later be used in electron.js for building a cross-platform application.</p>
  
  <p>The basic idea is:</p>
  
  <p>The user is presented with a webpage that shows his/her webcam feed. S/he can click on the capture button which will save the image on the server side. This will be repeated a number of times to get training data to train the facial recognition model. I implemented the image capture part using a third-party npm module called 'node-webcam': </p>
  
  <pre><code>const nodeWebCam = require('node-webcam');
  const fs = require('fs');
  const app = require('express')();
  const path = require('path');
  
  // specifying parameters for the pictures to be taken
  var options = {
      width: 1280,
      height: 720, 
      quality: 100,
      delay: 1,
      saveShots: true,
      output: "jpeg",
      device: false,
      callbackReturn: "location"
  };
  
  // create instance using the above options
  var webcam = nodeWebCam.create(options);
  
  // capture function that snaps &lt;amount&gt; images and saves them with the given name in a folder of the same name
  var captureShot = (amount, i, name) =&gt; {
      var path = `./images/${name}`;
  
      // create folder if and only if it does not exist
      if(!fs.existsSync(path)) {
          fs.mkdirSync(path);
      } 
  
      // capture the image
      webcam.capture(`./images/${name}/${name}${i}.${options.output}`, (err, data) =&gt; {
          if(!err) {
              console.log('Image created')
          }
          console.log(err);
          i++;
          if(i &lt;= amount) {
              captureShot(amount, i, name);
          }
      });  
  };
  
  // call the capture function
  captureShot(30, 1, 'robin');
  
  app.get('/', (req, res) =&gt; {
      res.sendFile(path.join(__dirname, 'index.html'));
  });
  
  app.listen(3000, () =&gt; {
      console.log("Listening at port 3000....");
  });
  </code></pre>
  
  <p>However, I am lost after this part. I don't know how to get the live feed to be displayed on the webpage which the user sees. Also, I realized later that this is a server side code, and there is no way to call the captureShot() function from client side. Any help would be appreciated.</p>