Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Node.js Express Instagram API Profile & Timeline Posts Scraper in Browser Using Javascript

Posted on January 17, 2023

 

 

Welcome folks today in this blog post we will be displaying the instagram user profile and timeline 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-scraping

 

 

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
21
22
<!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 Posts: <%=data.total%></h3>
        <h3>Biography: <%=data.user.biography%></h3>
        <h3>Full Name: <%=data.user.full_name%></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

 

 

JavaScript
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
const express = require('express')
const app = express()
const bodyparser = require('body-parser')
const ig = require('instagram-scraping')
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)
    ig.scrapeUserPage(username)
    .then((result) => {
        console.log(result)
        res.render('index',{data:result})
    })
})
 
app.listen(5000,() => {
    console.log("App is listening on port 5000")
})

 

 

As you can see we are getting the profile of the instagram user using the username which is given inside the post request and then we are sending the data to the ejs template

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme