1

I want to download file from other website to my pc using expressjs

I tried to use: res.download to download but it seems to be worked on my own server only

Here is my code:

res.download('http://apkleecher.com/download/dl.php?dl=com.instagram.android', 'folder', function(err){ if (err) { console.log(err); } else { } }); 

And it return the error:

{ Error: ENOENT: no such file or directory, stat '/home/keitaro/Desktop/google-play/http:/apkleecher.com/download/dl.php?dl=com.instagram.android' errno: -2, code: 'ENOENT', syscall: 'stat', path: '/home/keitaro/Desktop/google-play/http:/apkleecher.com/download/dl.php?dl=com.instagram.android', expose: false, statusCode: 404, status: 404 }

In my guess, the problem is in the path of url.

2
  • 1
    You probably want the request() module. Commented Nov 13, 2017 at 9:00
  • @jfriend00 yes, this is the correct answer Commented Nov 14, 2017 at 6:50

3 Answers 3

1

Turning my comment into an answer since it worked for you...

You can fetch a resource from a remote web server using either http.get() or the request() module in node. If you like to use promises for your asynchronous operations, then the request-promise module is a promisified version of the request module and works great.

You can also use just plain http.get(), but it's a lot more work because you have to read the stream, rather the results yourself and install appropriate error handling, all of which the request() module does for you in one simple call.

Here's a simple example using the request-promise module:

const rp = require('request-promise'); rp('http://www.google.com').then(function (htmlString) { // Process html... }).catch(function (err) { // process error here }); 
Sign up to request clarification or add additional context in comments.

Comments

1

res.download requires a path to your local filesystem.

try this:

res.redirect("http://apkleecher.com/download/dl.php?dl=com.instagram.android")

Comments

0

best way to download remote file is use stream .its use small mount of memory

**npm i got** //======================== const got=require('got'); const fs=require('fs'); const path=require('path'); file_downloader(link,file_name){ var file_path = path.join(__dirname,file_name); await got.stream(encodeURI(link)) .on('response', async (data) => { //first response check headers like ['content-length'] }) .on('error', async (error) => { console.log("===========Stream Error======= "); console.log(error); console.log("===========//End Stream Error======= "); }) .on('downloadProgress', async (progress) => { console.log(file.name, progress); }) .pipe(fs.createWriteStream(file_path)); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.