Nodejs Instagram videos downloader not working

0 votes

I am working on downloading videos from Instagram. I have tried these two packages : https://www.npmjs.com/package/instagram-url-direct https://www.npmjs.com/package/instagram-save

Example of instagram-save

const save = require('instagram-save');

app.get('/i/download/mp4', (req, res) => { 
 const url = 'https://www.instagram.com/reel/CYgT8zHKQjp/?utm_medium=copy_link';
 save(url, 'myDir').then(res => {
   console.log(res.file);
 });
})

while doing this I am getting this error and my app crashed

node_modules\request\request.js:231
    return self.emit('error', new Error('options.uri is a required argument'))
                              ^

Error: options.uri is a required argument
    at Request.init (D:\YI2D\youtube-api\node_modules\request\request.js:231:31)
    at Request.RP$initInterceptor [as init] (D:\YI2D\youtube-api\node_modules\request-promise\lib\rp.js:123:25)
    at new Request (D:\YI2D\youtube-api\node_modules\request\request.js:127:8)
    at request (D:\YI2D\youtube-api\node_modules\request\index.js:53:10)
    at Function.head (D:\YI2D\youtube-api\node_modules\request\index.js:61:12)
    at D:\YI2D\youtube-api\node_modules\instagram-save\lib\download-and-save.js:13:13
    at new Promise (<anonymous>)
    at downloadAndSave (D:\YI2D\youtube-api\node_modules\instagram-save\lib\download-and-save.js:12:10)
    at D:\YI2D\youtube-api\node_modules\instagram-save\index.js:23:9
[nodemon] app crashed - waiting for file changes before starting...

Any other way to do this?

Jun 8 in Node-js by Vaani
• 7,020 points
73 views

1 answer to this question.

0 votes

Firstly,

  1. Initialize a package.json file with default values.
npm init -y

2. Install the NPM packages that is needed

npm i express cors axios cheerio

If you’ve never used Node.js — the Express package gives us a server, Cors allows us to make requests from different origins(i.e if you had a frontend app on abc.com and your server was on def.com, CORS is the package that allows our server accept requests from different origins). Axios is the package for visiting a website and finally Cheerio is the package for inspecting and scraping elements on a Webpage.

3. Your start script should be changed to

node scraper.js

4. Let’s write the code. Create a scraper.js file in the root of your project. First we bring in our packages — express, cors, axios and cheerio.

We also need to call the app.use() method. This function calls all our middlewares. Think of middlewares as any function you want to run on every single request to our server. First, we call express.json() — this ensures that the requests coming into the server are in the JSON format. Secondly we call Cors() to ensure that if our frontend and backend are on different origins, they can still talk to each other.

5. Next, we create a getVideo() function. This is function takes a URL. Goes to that URL(using axios) and returns the result/response/page of that URL to Cheerio for scraping.

6. Now that we have defined the function that goes to Instagram and returns the videoString, we need a way to accept the URL users send in. This is where our express server comes in. This will also be an asynchronous function — i.e we need to wait for the result of the getVideo() function before we can return a response to the user.

7. And that’s it. We’re done. We can test our endpoint with postman.

The entire code for the frontend and backend is available here. Make sure to clone and star the repo.

There is another article on testing this app or any other Node.js app here.

answered Jun 9 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,560 points
11 views
0 votes
0 answers

Mongodb updateMany() not working in nodejs

I have a collection called imported_products with ...READ MORE

Jun 27 in Node-js by Vaani
• 7,020 points
32 views
0 votes
1 answer

Error:npm not working after clearing cache

Hello @kartik, Try this: npm cache clean --force OR It ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,740 points
4,358 views
0 votes
1 answer

Is there a way to download videos from YouTube Studio using NodeJS

Try this project in the github repository ...READ MORE

answered May 27 in Node-js by Neha
• 8,560 points
112 views
0 votes
0 answers

How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)

My node version is: node -v v0.6.1-pre Then I install ...READ MORE

May 16 in Java-Script by Kichu
• 19,040 points
125 views
0 votes
1 answer

Nodejs instagram-web can't save login session locally

There are several things you can do: Dictionary ...READ MORE

answered May 27 in Node-js by Neha
• 8,560 points
70 views
0 votes
1 answer

How to use npm jquery module?

To use jquery in node, you need ...READ MORE

answered Jun 21 in JQuery by rajatha
• 7,040 points
39 views
0 votes
1 answer

Nodejs: question of type input with npm inquirer not working

The right code should be: const outPath = ...READ MORE

answered Jun 7 in Node-js by Neha
• 8,560 points
105 views
0 votes
1 answer

NodeJS express get request is not working on mobile

For your API call, try to add ...READ MORE

answered Jun 7 in Node-js by Neha
• 8,560 points
81 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP