npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@paradoxepoch/node-file-downloader

v1.1.0

Published

Simple file downloader module for Node.js

Downloads

8

Readme

node-file-downloader

Simple file downloader module for Node.js

Installation

npm install @paradoxepoch/node-file-downloader

Usage

import fileDownload from '@paradoxepoch/node-file-downloader';
await fileDownload(url, filePath, options);

| Parameter | Type | Required | Description | | --------- | ------------------ | -------- | --------------------------------------------------------------- | | url | string | yes | The url of the file to download | | filePath | string or null | no | The local path to download the file to. Defaults to null. If falsy, downloads to a random filename in the system's temp directory | | options | string | no | The options object. Used to specify custom options to use for the download |

Examples

Simple download to local temp directory

The easiest way to use this module. Simply specify the url parameter and the file will be downloaded with a random name to your local temp directory on the system.

// Download to temp directory with random file name
const outputPath = await fileDownload('https://example.com/dummy.pdf');

// Log the path that the file was saved to
// eg: /tmp/tmp-21596-AnUG7d8LM75X-.pdf
// eg: C:\Users\User\AppData\Local\Temp
console.log(outputPath);

Simple download to specified path

Another easy way to use the module. Just specify the url and filePath parameters to download the file to a local path on the system.

// Download to specified path
const outputPath = await fileDownload('https://example.com/dummy.pdf', '/path/to/file.pdf');

// Log the path that the file was saved to
// /path/to/file.pdf
console.log(outputPath);

If the file extension is omitted from the filePath, the extension will automatically be appended to the output file based on the Content-Disposition header or extension in the download URL if present. This behaviour can be disabled by setting the appendMissingExtension option to false.

// Download to specified path (note the missing file extension in the filePath param)
const outputPath = await fileDownload('https://example.com/dummy.pdf', '/path/to/file');

// Log the path that the file was saved to
// /path/to/file.pdf
console.log(outputPath);

Download to local temp directory with custom options

Passing filePath as null (or any falsy value) will allow you to specify the options object while still downloading the file to the local temp directory with a random filename.

// Download to a specified directory with custom options
const filePath = await fileDownload('https://example.com/dummy.pdf', null, {
  successMsg: 'All good!',
  errorMsg: 'Something went wrong',
  httpMethod: 'post',
  showProgressBar: false
});

Options

| Property | Type | Default | Description | | ---------------------- | ----------------------- | ------------------------------ | --------------------------------------------------------------- | | startMsg | string | "Starting download..." | The message shown in the console when the download is starting. If falsy, no message is shown. | | downloadMsg | string | "Downloading, please wait..." | The message shown in the console when the file is downloading. If falsy, no message is shown. | | successMsg | string | "Download completed" | The message shown in the console when the download completes. If falsy, no message is shown. | | errorMsg | string | "Download failed" | The message shown in the console if the download fails. If falsy, no message is shown. | | appendMissingExtension | boolean | true | If true, appends file extension based on response headers or the URL if the save path does not include one. This option is ignored when filePath is falsy. | | httpMethod | string | "get" | The HTTP method to use for the download. Defaults to "get". | | appendHeaders | object | {} | An object containing custom headers to send with the request. | | showProgressBar | boolean | true | If true, displays a progress bar when the server includes a "Content-Length" header. | | throwOnFail | boolean | true | If true, throws an error if the download fails. If false, the error is only logged to the console as errorMsg and returns null. |