Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including download-to-file with all npm packages installed. Try it out:

var downloadToFile = require("download-to-file")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

download-to-file v2.1.0

Download a file to disk programmatically

download-to-file

Download a file to disk programmatically.

Build status js-standard-style

Installation

npm install download-to-file --save

Usage

var download = require('download-to-file')

console.log('Downloading to /tmp/example.html')
download('http://example.com/', '/tmp/example.html', function (err, filepath) {
  if (err) throw err
  console.log('Download finished:', filepath)
})

API

download(url, filepath, callback)

Will download the content of the given url and store it in a file specified by filepath. When done, the callback will be called with an optional error object as the first argument and the filepath as the second argument.

If the server does not return a 200 HTTP status code, the callback will be called with an error and the file will not be stored on disk.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free