javascript - require filename while downloading file using request module nodejs -


I use the request module in nodes to download the file (image file only) using this I'm doing,

  request ('http://google.com/doodle.png'). Pipe (fs.createWriteStream ('doodle.png')),   

or

  request (url) .pipe (fs.createWriteStream (filename)) ,   

But I only have url available and I need it to protect the file from its real name, so I must get the file name from the given url,

Please suggest to me how the last part of the URL has been removed

Thank you in advance ...

A simple solution can be:

  var path = required ('path'); Var FS = Requirement ('FS'); // ... var filename = path.basename (url); Request (url) .pipe (fs.createWriteStream (file name));    

Comments

Popular posts from this blog

Out of index C/C++ -

regex - PatternSyntaxException: while using String.ReplaceAll function in java? -

java - Projects which are accessed via multiple (different) IDEs: Ant or Maven? -