How to get YouTube channel id using Node.js ?
Last Updated :
24 Jul, 2024
The following approach covers how to get the YouTube channel Id using NodeJS. We will use the @gonetone/get-youtube-id-by-url node-package to achieve so. This package will help us for getting the YouTube channel id by using the channel URL.
Use the following steps to install the module and get the YouTube channel Id in node.js:
Step 1: Creating a directory for our project and making that our working directory.
$ mkdir channel-id-gfg
$ cd channel-id-gfg
Step 2: Use the npm init command to create a package.json file for our project.
$ npm init
OR
$ npm init -y /* For auto add the required field */

Note: Keep pressing enter and enter “yes/no” accordingly at the terminal line.
Step 3: Installing the Express.js and @gonetone/get-youtube-id-by-url module. Now in your channel-id-gfg(name of your folder) folder type the following command line:
npm install express @gonetone/get-youtube-id-by-url

Step 4: Creating index.js and index.html files, our project structure will look like this.

Step 5: Creating a basic server. Write down the following code in the index.js file.
index.js
const express = require('express');
const app = express();
app.get('/' , (req , res)=>{
res.send("GeeksforGeeks");
});
// Server setup
app.listen(4000 , ()=>{
console.log("server is running on port 4000");
});
Output:
GeeksforGeeks
Step 6: Now let's implement the functionality by which we get the YouTube channel Id. Here we are using the channelId method, which is available in @gonetone/get-youtube-id-by-url.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content=
"width=device-width, initial-scale=1.0" />
<title>YouTube Channel Id</title>
<style>
h1 {
color: green;
}
input {
width: 200px;
height: 20px;
margin: 10px;
}
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<form method="post" action="/channel-id">
<input
type="text"
name="url"
placeholder="Enter channel URL"
required
/>
<br />
<button type="submit">Get Channel Id</button>
</form>
</center>
</body>
</html>
index.js
const express = require("express");
const { channelId } = require("@gonetone/get-youtube-id-by-url");
const bodyParser = require("body-parser");
const app = express();
app.use(
bodyParser.urlencoded({
extended: true,
})
);
// Home Route
app.get("/", (req, res) => {
res.sendFile(__dirname + "/views/index.html");
});
// Channel Id route
app.post("/channel-id", (req, res) => {
const url = req.body.url;
channelId(url)
.then((id) => {
//Success
const response =
`<center><h2>Channel Id is - ${id}</h2><center>`;
res.send(response);
})
.catch((err) => {
// Error
res.send("Some error occurred");
});
});
app.listen(4000, () => {
console.log("Server running on port 4000");
});
Step 7: Run the server using the following command.
node index.js
Output: Now open http://localhost:4000 on your browser to see the below output.
Reference: https://www.npmjs.com/package/@gonetone/get-youtube-id-by-url
Similar Reads
How to get YouTube video thumbnail using Node.js ? The following approach covers how to get the YouTube video thumbnails in nodeJs. We will use the youtube-thumbnail node-package to achieve so. This package will help us for getting the YouTube video thumbnail with the help of the video URL or watch code.Use the following steps to install the module
2 min read
How to add Youtube Videos in Next.js ? In this article, we are going to learn how we can add Youtube Video in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components condit
2 min read
How to report a YouTube Video, User, or Channel Reporting a YouTube video, user, or channel is crucial for maintaining a safe and respectful environment on the platform. Whether you come across harmful content, spam, or violations of YouTubeâs community guidelines, knowing how to report a YouTube video or how to report a YouTube user can help you
7 min read
How to Download a File Using Node.js? Downloading files from the internet is a common task in many Node.js applications, whether it's fetching images, videos, documents, or any other type of file. In this article, we'll explore various methods for downloading files using Node.js, ranging from built-in modules to external libraries.Using
3 min read
How to generate unique ID with node.js? In this article, we are going to learn how to generate a unique ID using Node.js. Unique ID means a string contains a unique identity throughout the program. Table of Content Using UUIDUsing CryptoPrerequisitesJavaScript Node JSApproach 1: Using UUIDUUID is a module of NPM (Node Package Manager). UU
1 min read
How to Get Information About a File using Node.js ? Node.js is an open-source and cross-platform runtime environment built on Chromeâs V8 JavaScript engine for executing JavaScript code outside of a browser. You need to recollect that NodeJS isnât a framework, and itâs not a programming language. In this article, we will discuss how to get informatio
3 min read
How to Get Count of Instagram followers using Node.js ? To get the count of Instagram followers using Node.js, you can use several approaches. The most common methods involve using Instagram's unofficial APIs, scraping data from Instagram, or leveraging third-party APIs that provide access to Instagram data. Instagram's official API requires you to have
2 min read
How to Use ChatGPT API in NodeJS? ChatGPT is a very powerful chatbot by OpenAI that uses Natural Language Processing to interact like humans. It has become very popular among developers and is being widely used for some of its state-of-the-art features, like understanding and interpreting code, and even generating code based on text
4 min read
How to determine the user IP address using node.js ? Node.js is an open-source, back-end JavaScript runtime environment that runs on the web engine and executes JavaScript code. There are various platforms such as Windows, Linux, Mac OS Â where Node.js can run. The Domain Name System is a hierarchical and decentralized naming system for computers etc t
2 min read
How to see YouTube Analytics for other Channels YouTube Analytics serves as the compass for content creators, guiding them through the vast landscape of video performance. Understanding the basics of YouTube Analytics is crucial for maximizing the potential of your channel. In this comprehensive guide, we'll explore the key metrics, reports, and
15+ min read