Welcome folks today in this blog post we will be displaying the instagram user total followers
using the username in node.js and express
using javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to make the new node.js
project using the below command as shown below
npm init -y
And after that you need to install the below libraries
using the below command as shown below
npm i express
npm i ejs
npm i instagram-followers
And after that you will see the below directory
structure of the final app as shown below
Now we need to create the views
folder and inside it create the index.ejs
file and copy paste the following html code as shown below
views/index.ejs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!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>Document</title> </head> <body> <form autocomplete="off" action="/getProfile" method="post"> <input type="text" name="username" placeholder="Enter the Username" required> <input type="submit" value="Get Profile"> </form> <%if(data){%> <div id="result"> <h3>Total Followers: <%=data%></h3> </div> <%}%> </body> </html> |
Now we need to create the index.js
file which will hold the javascript code for making the express
app
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
const express = require('express') const app = express() const bodyparser = require('body-parser') const followers = require('instagram-followers') app.use(bodyparser.urlencoded({extended:false})) app.use(bodyparser.json()) app.set('view engine','ejs') app.get('/',(req,res) => { res.render("index",{data:''}) }) app.post('/getProfile',(req,res) => { let username = req.body.username console.log(username) followers(username) .then((result) => { console.log(result) res.render('index',{data:result}) }) .catch((error) => { console.log(error) }) }) app.listen(5000,() => { console.log("App is listening on port 5000") }) |
As you can see we are getting the `total followers of instagram username and then displaying it inside the browser