Node.js Tutorial to Access User Webcam Using Navigator API Wrapper getusermedia Library Full Tutorial

 

Welcome folks today in this blog post we will be talking about how to access user webcam inside node.js using getusermedia library. All the source code of the application is given below. A step by step youtube video is also shown below.

 

 

Get Started

 

In order to get started we will be using module bundler called as browserify to build our application so globally install this library at the command prompt like this

 

npm i browserify -g

 

After installing it go to your project folder and make a index.html file like this and copy paste the code

 

<!DOCTYPE html>
<html>
<head>
<title>Webcam Node.js Tutorial</title>
</head>
<body>

</body>
<script src="bundle.js"></script>
</html>

 

See also  Node.js Express Tutorial to Send Email Messages With Attachments Using NodeMailer Full Project

 

Now here we are including the bundle.js file which have been generated by browserify so we need to install some dependencies first so for that go to your command prompt and type this

 

npm init -y

 

npm i getusermedia

 

After installing this inside your package.json file will contain a dependency section called getusermedia

Now make your index.js file and copy paste the following code

 

index.js

 

var getUserMedia = require('getusermedia')

getUserMedia({ video: true, audio: true }, function (err, stream) {
  if (err) return console.error(err)

  
    console.log(stream)
    var video = document.createElement('video')
    document.body.appendChild(video)

    video.srcObject=stream
    video.play()
  
})

 

 

 

 

 

 

 

Leave a Reply