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

node-wget-fetch

v1.1.3

Published

Ultra simple async retrieval of resources or remote files over http or https, an cli tool, and convenience wrapper of node-fetch, and a seamless retry ability

Downloads

1,006

Readme

node-wget-fetch

NPM

Dependencies Status Node.js CI codecov MaintainabilityRelease

Ultra simple async retrieval of resources or remote files over http or https, an cli tool, convenience wrapper of node-fetch, and a seamless retry ability.

Install

npm install node-wget-fetch

Basic API

fetching(url, action = destination | response_body_type | options [, options])

  • url A string representing an absolute url

  • action Save to destination or body action on response type or use for options

    response type can be:

    • 'header' for all response headers - raw()
    • 'object' for the response object - no post/pre processing
    • 'array' for arrayBuffer()
    • 'buffer' for buffer()
    • 'blob' for blob()
    • 'json' for json()
    • 'text' for text()
    • 'stream' for NodeJs.readableStream()

    default is 'download'

  • options Standard Request/Fetch Options for the HTTP(S) request

  • Returns: Promise of response body of above type, only if status text is OK.

  • The response type will set Fetch/Request header 'Content-Type' as:

    • 'json' = 'application/json; charset=utf-8'
    • 'text' = 'application/x-www-form-urlencoded'
    • 'blob' = 'application/octet'
    • 'buffer' = 'application/octet'
    • 'header' = 'text/plain'
    • 'object' = 'application/json; charset=utf-8'
    • 'stream' = 'application/octet'
    • 'array' = 'application/octet'

To customize retry Fetch operation, update in options.

retry:
{
    retries: 1, // The maximum amount of times to retry the operation.
    factor: 2, //The exponential factor to use.
    minTimeout: 1000, // The number of milliseconds before starting the first retry.
    maxTimeout: 'Infinity', // The maximum number of milliseconds between two retries.
    randomize: false, // Randomizes the timeouts by multiplying with a factor between 1 to 2.
 }

Convenience Request Methods

import { get, head, options } from 'node-wget-fetch';

get(url, response_body_type [, options]);

head(url, response_body_type [, options]);

options(url, response_body_type [, options);]

For simply submitting body data

Note: body data is passed in, handled by URLSearchParams class, if String or Object.

import { post, put, patch, delete } from 'node-wget-fetch';

post(url, body, response_body_type [, options]);

put(url, body, response_body_type [, options]);

patch(url, body, response_body_type [, options]);

delete(url, body, response_body_type [, options]);

Bring in or access node-fetch directly

fetching.fetch(url [, options]);

Usage

// CommonJS
const fetching = require('node-wget-fetch');
const wget = fetching.wget;

// ESM 12+
import { wget } from 'node-wget-fetch';

wget(url) // retrieve to current directory
    .then((info) => {});
    .catch((error) => {});

wget(url, { headers:  { Accept: '*/*' } }) // with optional `Fetch` options
    .then((info) => {});
    .catch((error) => {});

wget(url, destination_folder_or_filename, { timeout: 2000 } )  // with optional `Fetch` options
    .then((info) => {});
    .catch((error) => {});


fetching(url, responseType, // *responseType* can be:
    // 'header' for all response headers - raw()
    // 'object' for the response object - no post/pre processing
    // 'array' for arrayBuffer()
    // 'buffer' for buffer()
    // 'blob' for blob()
    // 'json' for json()
    // 'text' for text()
    // 'stream' for NodeJs.readableStream()
    // default is 'download'
    { headers: {Accept: '*/*' } }) // with optional `Fetch` options
    )
    .then((processedResponse) => {
        // No file is retrieved or saved,
        // an resolved `Fetch` response body of above type is returned
    });
    .catch((error) => {});

Examples

import { wget } from 'node-wget-fetch';

wget('https://raw.github.com/techno-express/node-wget-fetch/master/angleman.png'); // angleman.png saved to current folder

wget('https://raw.github.com/techno-express/node-wget-fetch/master/package.json',
    '/tmp/', // destination path or path with filename, default is ./
    { timeout: 2000 } // Any `Fetch` Options, this sets duration to wait for request in milliseconds, default 0
    )
    .then((info) => {
        console.log('--- headers:'); // display all response headers
        console.log(info.headers);
        console.log('--- file path:'); // display file retrieved info
        console.log(info.filepath);
        console.log('--- file size retrieved:');
        console.log(info.fileSize);
        console.log('--- Do file retrieved match "Content-Length"?:');
        console.log(info.fileSizeMatch);
    })
    .catch((error) => {
        console.log('--- error:');
        console.log(error); // error encountered
    });
);

CLI

Install:

npm install -g node-wget-fetch

Use:

Usage: wget [options] <url>

Or

Usage: fetch [options] <url>

Ultra simple async retrieval of remote files over http or https

Options:

  -h, --help                        output usage information
  -v, --version                     output version number
  -d, --destination <folder>        specify download destination

Usage:

# Download file
$ wget https://github.com/NodeOS/NodeOS/archive/master.zip
$ fetch https://github.com/NodeOS/NodeOS/archive/master.zip

# Download file to location
$ wget https://github.com/NodeOS/NodeOS/archive/master.zip -d path/to/here/
$ fetch https://github.com/NodeOS/NodeOS/archive/master.zip -d path/to/here/

License: MIT