How to make a video call app in node.js ?
Last Updated :
24 Jun, 2022
For making a video call app, It is required that each and every client send their video and audio stream to all the other clients. So for this purpose we are using Peer.js and for the communication between the clients and the server we are using WebSocket i.e. Socket.io.
Prerequisite: 1. Node.js: It is an open-source JavaScript Back-End technology. It has a package manager called npm- Node package manager which installs different packages very easily.
2. Express.js: It is a node.js server framework.
3. Socket.io:It helps us to create a real-time bi-direction event-based communication between the server and the client.
4. Peer.js: It helps us to send and receive the audio and video streams of the other clients.
Setting up the Environment: This is the very first step, here we are creating and initializing a new repository.
$ mkdir VideoCallApp
$ cd VideoCallApp
$ npm init
Now, the next step is to install the required packages for our VideoCallApp.
- Express : It is the server-based framework for node.js
- ejs : It is a simple templating language that lets you generate HTML markup with plain JavaScript.
- Socket.io : It manages the Websocket for event-based communication.
- Nodemon (optional): It automatically restarts the server when you save your project files.
- uuid module: This module is used to generate a unique id. This will be used in this project
Installing the required modules:
$ npm install express
$ npm install ejs
$ npm install socket.io
$ npm install nodemon
Now, we all set for the implementation part.
Implementation:
Step 1: Create a server file — server.js
JavaScript
// Importing express module
const express = require('express');
const app = express();
app.set("view engine", "ejs");
// Calling the public folder
app.use(express.static("public"));
// Handling get request
app.get("/" , (req,res)=>{
res.send("Welcome to GeeksforGeeks Video Call App");
});
// Listing the server
app.listen(4000 , ()=>{
console.log("Server running on port 4000");
})
Execution command for server.js
node server.js
Now, If you open the local host i.e. localhost:4000 You will see the output i.e. — Welcome to GeeksforGeeks Video Call App.

Now, For socket.io we need to write some more code. Here, we added code for socket.io and we just change app.listen() to server.listen() methods.
Now we are all set for the client side development.
JavaScript
const server = require('http').Server(app);
const io = require('socket.io')(server);
server.listen(4000 , ()=>{
console.log("Server running on port 4000");
);
Step2: Create two folders one is public and the second is views.
Project structure:

- Now in views create an index.ejs file which contains all html code.
- Here, we added three script files, first one is for peerjs, the second one is for socket.io and the last one is our main index.js file.
Index.ejs file
HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>Video App</title>
<style media="screen">
* {
margin: 0;
}
#videoDiv {
display: grid;
grid-gap: 10px;
height: 80%;
position: relative;
grid-template-columns: repeat(auto-fill, 300px);
grid-auto-rows: 300px;
}
#footer {
width: 100%;
height: 50px;
background-color: white;
display: flex;
justify-content: center;
flex: 1;
border-bottom: 1px solid grey;
margin-top: 10px;
}
button {
height: 30px;
width: 80px;
margin-top: 10px;
text-align: center;
border-radius: 10px;
outline: none;
border: none;
text-decoration: none;
background-color: red;
cursor: pointer;
}
video {
width: 100%;
height: 100%;
object-fit: cover;
border: 2px solid white;
}
</style>
<script type="text/javascript">
var roomID = "<%= RoomId %>"
</script>
<script src=
"https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"
defer>
</script>
<script src="socket.io/socket.io.js" defer>
</script>
<script src="index.js" charset="utf-8" defer>
</script>
</head>
<body>
<div id="videoDiv"></div>
</body>
</html>
Note — you can create your own UI, I created a simple one.
- Now in the public folder create an index.js file for your index.ejs file and write some code.
const socket = io('/');
const peer = new Peer();
peer.on('open' , (id)=>{
socket.emit("newUser" , id);
});
So whenever the new user will get connected they will get a unique id through the peer.js and after that it emits a socket event for the server i.e newUser.
So to handle this event we need to add some more code in our server-side.
JavaScript
io.on('connection' , (socket)=>{
socket.on('newUser' , (id)=>{
socket.join('/');
socket.to('/').broadcast.emit("userJoined" , id);
});
});
Now when this event occurs the server will tell all the other clients that the new user is connected.
Let's Implement the main function of this app -
Now we are going to take users audio, video streams and send that stream to another client. For this, we are going to use WebRTC here.
Code to take video and audio of the user-
JavaScript
navigator.mediaDevices.getUserMedia({
video:true,
audio:true
}).then((stream)=>{
// Some more code
}).catch(err=>{
alert(err.message)
})
Now we need to send the stream to all other clients, so let's implement that part-
Here we have a peer.js method named as call. It will call the other client to send and receive streams.
Client 1: Client 1 will call client 2 as shown below.
JavaScript
socket.on('userJoined' , id=>{
console.log("new user joined")
// Calling other client and sending our stream
const call = peer.call(id , myVideoStream);
const vid = document.createElement('video');
call.on('error' , (err)=>{
alert(err);
})
// Taking the stream of the other client
// when they will send it.
call.on('stream' , userStream=>{
// addVideo is a function which append
// the video of the clients
addVideo(vid , userStream);
})
Client 2: let's see how client 2 will respond to the client 1 call.
JavaScript
peer.on('call' , call=>{
// Here client 2 is answering the call
// and sending back their stream
call.answer(stream);
const vid = document.createElement('video');
// This event append the user stream.
call.on('stream' , userStream=>{
addVideo(vid , userStream);
})
call.on('error' , (err)=>{
alert(err)
})
})
Now after sending and receiving the streams of both the clients the output will be -
Output -
OUTPUT
Note — You can deploy it on any platform you want, In my case I deployed it on heroku.com
For source code please click here, Also it is a basic one you can modify it as you want.
Similar Reads
AI and Machine Learning
Web and API Development
How to build Node.js Blog API ?In this article, we are going to create a blog API using Node.js. A Blog API is an API by which users can fetch blogs, write blogs to the server, delete blogs, and even filter blogs with various parameters.Functionalities:Fetch BlogsCreate BlogsDelete BlogsFilter BlogsApproach: In this project, we w
4 min read
RESTful Blogging API with Node and Express.jsBlogs Websites have become very popular nowadays for sharing your thoughts among the users over internet. In this article, you will be guided through creating a Restful API for the Blogging website with the help of Node, Express, and MongoDB.Prerequisites:Node JS & NPMExpress JSMongoDBApproach t
5 min read
Build a Social Media REST API Using Node.js: A Complete GuideDevelopers build an API(Application Programming Interface) that allows other systems to interact with their Applicationâs functionalities and data. In simple words, API is a set of protocols, rules, and tools that allow different software applications to access allowed functionalities, and data and
15+ min read
Finance and Budgeting
Communication and Social Platforms
Health and Medical
Management Systems
Customer Relationship Management (CRM) System with Node.js and Express.jsCRM systems are important tools for businesses to manage their customer interactions, both with existing and potential clients. In this article, we will demonstrate how to create a CRM system using Node.js and Express. We will cover the key functionalities, prerequisites, approach, and steps require
15+ min read
Library Management Application BackendLibrary Management System backend using Express and MongoDB contains various endpoints that will help to manage library users and work with library data. The application will provide an endpoint for user management. API will be able to register users, authenticate users, borrow books, return books,
10 min read
How to Build Library Management System Using NodeJS?A Library Management System is an essential application for managing books, users, and transactions in a library. It involves adding, removing, updating, and viewing books and managing users. In this article, we will walk through how to build a simple Library Management System using NodeJS.What We A
6 min read
Student Management System using Express.js and EJS Templating EngineIn this article, we build a student management student which will have features like adding students to a record, removing students, and updating students. We will be using popular web tools NodeJS, Express JS, and MongoDB for the backend. We will use HTML, CSS, and JavaScript for the front end. We'
5 min read
Subscription Management System with NodeJS and ExpressJSIn this article, weâll walk through the step-by-step process of creating a Subscription Management System with NodeJS and ExpressJS. This application will provide users with the ability to subscribe to various plans, manage their subscriptions, and include features like user authentication and autho
5 min read
Building a Toll Road Management System using Node.jsIn this article, we are going to build a simple Toll Road Management System using Node.js, where the data will be stored in a local MongoDB database.Problem Statement: In a toll tax plaza, it is difficult to record all the transactions and store them in a single place, along with that, if required,
15+ min read
How to Build User Management System Using NodeJS?A User Management System is an essential application for handling user accounts and information. It involves creating, reading, updating, and deleting user accounts, also known as CRUD operations. In this article, we will walk through how to build a simple User Management System using NodeJS.What We
6 min read
User Management System BackendUser Management System Backend includes numerous endpoints for performing user-dealing tasks. The backend could be constructed with the use of NodeJS and MongoDB with ExpressJS . The software will offer an endpoint for consumer management. API will be capable of registering, authenticating, and cont
4 min read
File and Document Handling
Build a document generator with Express using REST APIIn the digital age, the need for dynamic and automated document generation has become increasingly prevalent. Whether you're creating reports, invoices, or any other type of document, having a reliable system in place can streamline your workflow. In this article, we'll explore how to build a Docume
2 min read
DOCX to PDF Converter using ExpressIn this article, we are going to create a Document Conversion Application that converts DOCX to PDF. We will follow step by step approach to do it. We also make use of third-party APIs.Prerequisites:Express JS multernpm Preview of the final output: Let us have a look at how the final output will loo
4 min read
How to Send Email using NodeJS?Sending emails programmatically is a common requirement in many applications, especially for user notifications, order confirmations, password resets, and newsletters. In this article, we will learn how to build a simple email-sending system using NodeJS. We will use Nodemailer, a popular module for
5 min read
File Sharing Platform with Node.js and Express.jsIn today's digital age, the need for efficient File sharing platforms has become increasingly prevalent. Whether it's sharing documents for collaboration or distributing media files, having a reliable solution can greatly enhance productivity and convenience. In this article, we'll explore how to cr
4 min read
React Single File Upload with Multer and Express.jsWhen we want to add functionality for uploading or deleting files, file storage becomes crucial, whether it's for website or personal use. The File Storage project using Express aims to develop a web application that provides users with a secure and efficient way to store and manage their files onli
5 min read
Entertainment and Media
Task and Project Management
Task Management System using Node and Express.jsTask Management System is one of the most important tools when you want to organize your tasks. NodeJS and ExpressJS are used in this article to create a REST API for performing all CRUD operations on task. It has two models User and Task. ReactJS and Tailwind CSS are used to create a frontend inter
15+ min read
Task Manager App using Express, React and GraphQL.The Task Manager app tool is designed to simplify task management with CRUD operation: creation, deletion, and modification of tasks. Users can easily generate new tasks, remove completed ones, and update task details. In this step-by-step tutorial, you will learn the process of building a Basic Tas
6 min read
Simple Task Manager CLI Using NodeJSA Task Manager is a very useful tool to keep track of your tasks, whether it's for personal use or a work-related project. In this article, we will learn how to build a Simple Task Manager CLI (Command Line Interface) application using Node.js.What We Are Going to Create?We will build a CLI task man
5 min read
Task Scheduling App with Node and Express.jsTask Scheduling app is an app that can be used to create, update, delete, and view all the tasks created. It is implemented using NodeJS and ExpressJS. The scheduler allows users to add tasks in the cache of the current session, once the app is reloaded the data gets deleted. This can be scaled usin
4 min read
Todo List CLI application using Node.jsCLI is a very powerful tool for developers. We will be learning how to create a simple Todo List application for command line. We have seen TodoList as a beginner project in web development and android development but a CLI app is something we don't often hear about.Pre-requisites:A recent version o
13 min read
Real-Time Applications