# simpledownload

> call with `url` and `filename`, then download the file

Latest version **2.1.0** (published 2026-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install simpledownload
pnpm add simpledownload
yarn add simpledownload
bun add simpledownload
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-06-11 |
| First published | 2014-09-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=24 <25 |
| Dependencies | 0 |
| Unpacked size | 33.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | alsotang |
| Maintainers | alsotang |
| Keywords | download |

## Links

- npm: https://www.npmjs.com/package/simpledownload
- Repository: https://github.com/alsotang/simpledownload
- Issues: https://github.com/alsotang/simpledownload/issues
- npm.io page: https://npm.io/package/simpledownload

## Recent versions

- 2.1.0 (latest) — 2026-06-11
- 2.0.6 — 2024-10-08
- 2.0.5 — 2024-10-07
- 2.0.4 — 2022-03-15
- 2.0.3 — 2022-01-26
- 2.0.2 — 2022-01-26
- 2.0.1 — 2021-12-26
- 2.0.0 — 2021-12-24
- 1.0.3 — 2015-07-29
- 1.0.2 — 2015-07-29
- 1.0.1 — 2014-09-12
- 1.0.0 — 2014-09-12

## README

[![Node.js CI](https://github.com/alsotang/simpledownload/actions/workflows/node.js.yml/badge.svg)](https://github.com/alsotang/simpledownload/actions/workflows/node.js.yml)

## Install

`npm install simpledownload`

## Usage

```js
import {simpledownload} from 'simpledownload'
await simpledownload('https://www.google.co.jp/images/srpr/logo11w.png', `${__dirname}/1.jpg`);
```

### simpledownload(url: string, localPath: string, options?: {timeout, agent}): Promise\<void\>

* `url` - the url you wanna download. e.g `https://www.google.co.jp/images/srpr/logo11w.png`
* `localPath` - e.g `` `${__dirname}/1.jpg` ``
* `options.timeout` - timeout in milliseconds.
* `options.agent` - `http.Agent` or `https.Agent`. For example, you can use `node-socks-proxy-agent` to enable socks5 proxy.

## Error handling

```js
import {simpledownload, HttpStatusCodeError, TimeoutError} from 'simpledownload'

try {
  await simpledownload('https://example.com/file.jpg', `${__dirname}/1.jpg`, {
    timeout: 5000,
  });
} catch (err) {
  if (err instanceof HttpStatusCodeError && err.statusCode === 404) {
    // handle not found
  } else if (err instanceof TimeoutError) {
    // handle timeout
    console.log(err.timeout);
  } else {
    throw err;
  }
}
```

Redirect responses (`3xx`) with a `Location` header are followed automatically.
After redirects, any non-2xx response rejects with `HttpStatusCodeError`, so callers can check `err.statusCode`.
If the download times out, it rejects with `TimeoutError`, so callers can check `err.timeout`.


## dev

1. `$ npm run test`
2. bump package.json version
3. `$ npm publish`

## license

MIT

---
_Source: https://npm.io/package/simpledownload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
