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

universal-file-downloader

v1.0.5

Published

Cool repository to download file in nodejs && deno && browser

Downloads

39

Readme

universal-file-downloader

MIT license image

Table of Contents

  1. Description
  2. Installation
  3. Usage 3.1 Basic example 3.2 Store file in another foler 3.3 Configure fetch parameter 3.4 Using a server proxy 3.5 Download with less request
  4. Browser 4.1 Download File from browser 4.2 Install via cdn 4.3 Setup Proxy
  5. License

Description

Repository to download file from everywhere !!!

It's work in the browser / nodejs / deno

If you want to use it in node js you need to specify "type" : "module" in your package.json

Installation

You can install this package via npm:

npm install universal-file-downloader

Usage

Basic Example

Here is a basic usage example :

import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file').downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')

Store file in another folder

If you want to store the file in another folder

import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file').downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')

Configure Fetch Param

Maybe you want the file you request need to be done via POST

import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file', { method : 'POST'}).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')

Using a server proxy

It's possible that you want to use a server proxy

import ufd from 'universal-file-downloader'
await new ufd('my_file.extension_file', {}, { url : 'my.server.proxy.com/', headers : {}}).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4')

With the given configuration the url forward will become my.server.proxy.com/https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4

Be sure to configure the url as you need

Browser

Download file from browser

Downloading from the browser is more tricky : slower than in back-end (cause browser api doesn't allow stream to blob without interruption) and require a proxy (Hello CORS) I advise you to download the video in the back-end and create a tmp link that you will return to your user then create a Blob and a download link But If you can't / don't want to use the back-end way, use the following code who is working well

<!DOCTYPE html>
<html>
<head>
    <title>Test Page</title>
</head>
<body>
    <button>Download</button>
</body>
<script type="module">
    import ufd from './node_modules/universal-file-downloader/dist/index.mjs';
    document.querySelector('button').addEventListener('click', async () => {
        const filename = "test.mp4";
        const proxyOptions = {
            url : 'http://localhost:8080/',
            headers : {'X-Requested-With' : 'XMLHttpRequest' }
        };
        await new ufd('toto.mp4', {}, proxyOptions).downloadFile('https://sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4');
    });
</script>
</html>

Install via CDN

You can also use the cdn version if you don't want to use install this package

<script type="module">
    import Inspector from 'https://cdn.jsdelivr.net/npm/universal-file-downloader/dist/index.mjs';
</script>

Setup proxy

If you are looking for a plugin to bypass cors i advise you tiny-cors-proxy

You can install this package via npm:

npm install tiny-cors-proxy

Then create a new file server.js and paste the following snipset :

import corsServer from 'tiny-cors-proxy';
corsServer.listen(8080);

Run the following command

node server.js

License

This project is licensed under the MIT license