Open In App

How to get count of Instagram followers using Node.js ?

Last Updated : 24 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The following approach covers how to get the count of Instagram followers in nodeJs. We have used the instagram-followers package to achieve so. This package help’s us by getting the count of Instagram followers with the help of the username.

Use the following steps to install the module and get the count of Instagram followers in node.js:

Step 1: Creating a directory for our project and making that our working directory.

$ mkdir node-app
$ cd node-app

Step 2: Use the npm init command to create a package.json file for our project.

$ npm init

Note: Keep pressing enter and enter “yes/no” accordingly at the terminus line.

Step 3: Installing the Express.js and instagram-followers module. Now in your node-app(name of your folder) folder type the following command line:

$ npm install express instagram-followers

Step 4: Creating index.js file, 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: We will get the following output on the browser screen.

GeeksforGeeks

Step 6: Now let’s implement the functionality by which we get the Instagram follower’s count.

index.js




const express = require('express');
const followers = require('instagram-followers');
const app = express();
    
app.get('/' , (req , res)=>{
    res.send("GeeksforGeeks");
});
    
app.get('/:username' , (req , res) => {
    followers(req.params.username).then((count) => {
        if(!count){
            res.send("Account Not Found");
            return;
        }
        res.send("Username " + req.params.username + 
            " have " + "<b>" +  count + "</b>" + " followers");
  
    });
});
  
// Server setup
app.listen(4000 , ()=>{
    console.log("server is running on port 4000");
});


Step 7: Run the server using the following command.

node index.js

Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads