# node-base64-image

> Download images from remote URLs and encode/decode them to base64

Latest version **3.0.0** (published 2026-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-base64-image
pnpm add node-base64-image
yarn add node-base64-image
bun add node-base64-image
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-05-10 |
| First published | 2014-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | Riyadh Al Nur |
| Maintainers | riyadhalnur |
| Keywords | image, download, base64, encode, decode, javascript, typescript, node, nodejs, js, buffer |

## Links

- npm: https://www.npmjs.com/package/node-base64-image
- Repository: https://github.com/riyadhalnur/node-base64-image
- Homepage: https://riyadhalnur.github.io/node-base64-image/
- Issues: https://github.com/riyadhalnur/node-base64-image/issues
- npm.io page: https://npm.io/package/node-base64-image

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.16.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.0.0 (latest) — 2026-05-10
- 2.2.0 — 2025-04-23
- 2.1.0 — 2025-04-16
- 2.0.7 — 2024-08-15
- 2.0.6 — 2023-11-12
- 2.0.5 — 2023-04-13
- 2.0.4 — 2022-01-29
- 2.0.3 — 2021-01-20
- 2.0.2 — 2021-01-18
- 2.0.1 — 2020-05-25
- 2.0.0 — 2020-05-25
- 1.0.7 — 2020-02-12
- 1.0.6 — 2019-06-01
- 1.0.5 — 2018-04-22
- 1.0.4 — 2017-07-07
- … 7 more at https://npm.io/package/node-base64-image/versions

## README

![Node.js Package](https://github.com/riyadhalnur/node-base64-image/workflows/Node.js%20Package/badge.svg?branch=master)  
![NPM Version](https://img.shields.io/npm/v/node-base64-image)
![NPM Downloads](https://img.shields.io/npm/dw/node-base64-image)
# node-base64-image

Easily encode images (from URLs or local files) to Base64 strings or [Buffer](https://nodejs.org/api/buffer.html) objects, and decode them back into image files.

### Installation
```
npm install node-base64-image --save
```

Usage
-----
```js
// CommonJS:
const { encode, decode } = require('node-base64-image');

// ES Modules / TypeScript:
import { encode, decode } from 'node-base64-image';
```

EncodeOptions
---
| Attribute | Type     | Description                                | Default Value |
|-----------|----------|--------------------------------------------|---------------|
| string    | boolean  | If true, returns a base64 string            | false         |
| local     | boolean  | Set to true to read from a local file       | -             |
| timeout   | number   | Request timeout in milliseconds             | 5000          |
| headers   | object   | Optional headers for remote HTTP requests   | -             |


DecodeOptions (Required)
---
| Attribute | Type   | Description                           | Default Value |
|-----------|--------|---------------------------------------|---------------|
| fname     | string | Output filename (without extension)   | -             |
| ext       | string | File extension (e.g., jpg, png)       | -             |

Examples
--------
```js
// encoding a remote jpg to base64
const url = 'https://example.com/test.jpg';
const options = {
  string: true,
  headers: {
    "User-Agent": "my-app"
  }
};
const image = await encode(url, options);

// encoding a local file
const localUrl = 'C:/project/test.jpg';
const localImage = await encode(url, {string: true, local: true});

// writing to file named 'example.jpg'
await decode(image, { fname: 'example', ext: 'jpg' });

// writing to a sub-directory
// after creating a directory called 'photos'
const image = await encode(url, options);
await decode(image, { fname: './photos/example', ext: 'jpg' });
```

### Contributing
Read the [CONTRIBUTING](CONTRIBUTING.md) guide for information.  

### License
Licensed under MIT. See [LICENSE](LICENSE) for more information.  

### Issues
Report a bug in [issues](https://github.com/riyadhalnur/node-base64-image/issues)

Made with love in Dhaka, Bangladesh by [Riyadh Al Nur](https://verticalaxisbd.com)

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