Using Wget in Node.js

Advertisement

Advertisement

There is a wget package available for Node.js that makes it really easy to integrate the convenience of wget in to a Node.js program. It is useful for downloading a file from any number of protocols. This example shows you how to download a file using wget in Node.js

It is important to note that the wget.download() function does not overwrite when it downloads, it appends. So, you should first check to see if a file exists and move it or delete it if you don't want it to append. See my post on File Manipulation with Node.js on how to do all of that. Also remember to install the wget package. There is also a newer more maintained version called wget-improved. Here is the official documentation for wget-improved.

npm install wget
# Or
npm install wget-improved

Wget Example

var wget = require('wget');
# Or
#var wget = require('wget-improved');

var source = 'http://www.devdungeon.com/archive';
var outputFile = 'devdungeon_archive.html';

wget.download(source, outputFile);

Advertisement

Advertisement