Socket
Socket
Sign inDemoInstall

node-wget-fetch

Package Overview
Dependencies
7
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-wget-fetch

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


Version published
Maintainers
1
Install size
506 kB
Created

Readme

Source

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, and convenience wrapper of node-fetch.

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()
    • 'converted' for textConverted()
    • '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

Convenience Request Methods

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

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

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

For simply submitting body data

fetching.post(url, body, action = response_body_type | options [, options])

fetching.put(url, body, action = response_body_type | options [, options])

fetching.patch(url, body, action = response_body_type | options [, options])

fetching.delete(url, body, action = response_body_type | options [, options])

Bring in or access node-fetch directly

fetching.fetch(url [, options])

Usage

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

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

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

fetching.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()
    // 'converted' for textConverted()
    // '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

const wget = require('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.retrievedSizeMatch);
    })
    .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

Keywords

FAQs

Last updated on 07 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc