# @therealbarenziah/imgbb-uploader

> Lightweight module to upload images through Imgbb API.

Latest version **1.1.2** (published 2020-08-17) · SEE LICENSE IN TARGARYEN_UNLICENSE license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @therealbarenziah/imgbb-uploader
pnpm add @therealbarenziah/imgbb-uploader
yarn add @therealbarenziah/imgbb-uploader
bun add @therealbarenziah/imgbb-uploader
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2020-08-17 |
| First published | 2019-11-22 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN TARGARYEN_UNLICENSE |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 48 |
| Author | TheRealBarenziah |
| Maintainers | therealbarenziah |
| Keywords | imgbb, imgbb-uploader, image upload, picture upload |

## Links

- npm: https://www.npmjs.com/package/@therealbarenziah/imgbb-uploader
- Repository: https://github.com/TheRealBarenziah/imgbb-uploader
- Homepage: https://github.com/TheRealBarenziah/imgbb-uploader#readme
- Issues: https://github.com/TheRealBarenziah/imgbb-uploader/issues
- npm.io page: https://npm.io/package/@therealbarenziah/imgbb-uploader

## Dependencies (1)

- [fs](https://npm.io/package/fs.md) 0.0.1-security

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2020-08-17
- 1.1.1 — 2020-08-17
- 1.1.0 — 2020-08-17
- 1.0.5 — 2020-08-17
- 1.0.4 — 2020-08-17
- 1.0.3 — 2020-08-16
- 0.1.0 — 2019-11-22

## README

# imgbb-uploader

Lightweight Nodejs module to upload local pictures files to imgbb API and get display URLs in response.  
Primary use is letting imgBB handle the hosting & serving of images.

[![https://nodei.co/npm/imgbb-uploader.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/imgbb-uploader.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/imgbb-uploader)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Known Vulnerabilities](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader/badge.svg?targetFile=package.json)](https://snyk.io/test/github/TheRealBarenziah/imgbb-uploader?targetFile=package.json)
[![Build Status](https://travis-ci.org/TheRealBarenziah/imgbb-uploader.svg?branch=master)](https://travis-ci.org/TheRealBarenziah/imgbb-uploader)

## Compatibility:

**Node >= 8** ( [this module uses async/await](https://node.green/) )  
_Care: this module uses `fs` under the hood. It means **it WON'T work outside the node environment !**_  
_To upload pictures from your frontend please check the [File API](https://developer.mozilla.org/en-US/docs/Web/API/File) instead_

## Install

`npm install imgbb-uploader`

## Use

- I) [Get a free API key from imgbb](https://api.imgbb.com/) ( estimated time ~1 minute )
- II) (facultative) [Put that in an environment variable](https://www.npmjs.com/package/dotenv)
- III) **imgbbUploader takes _exactly two_ String arguments** : your API key, and the absolute path of your image :

```
var imgbbUploader = require('imgbb-uploader');

imgbbUploader("your-imgbb-api-key-string", "home/absolute/path/to/your/image/image.png")
  .then(response => console.log(response))
  .catch(error => console.error(1))
```

## `.then(response => console.log(response))` output example :

```
{
  id: '5jKj6XV',
  url_viewer: 'https://ibb.co/5jKj6XV',
  url: 'https://i.ibb.co/94Z4Nmj/test.jpg',
  display_url: 'https://i.ibb.co/94Z4Nmj/test.jpg',
  title: 'test',
  time: '1574431312',
  image: {
    filename: 'test.jpg',
    name: 'test',
    mime: 'image/jpeg',
    extension: 'jpg',
    url: 'https://i.ibb.co/94Z4Nmj/test.jpg',
    size: 91264
  },
  thumb: {
    filename: 'test.jpg',
    name: 'test',
    mime: 'image/jpeg',
    extension: 'jpg',
    url: 'https://i.ibb.co/5jKj6XV/test.jpg',
    size: '12875'
  },
  delete_url: 'https://ibb.co/5jKj6XV/ffd8ef0b1c803f02443553535cf4a5f4'
}
```

This async function returns a promise, so this is normal :  
`console.log(imgbbUploader(myKey, myPath)) // output : Promise { <pending> }`  
Your data is available in `.then(response => response)` as shown above.

**This module is tiny & totally unlicensed: to better fit your need, feel free to fork !**  
[Basic instructions for tweaking](https://github.com/TheRealBarenziah/imgbb-uploader/blob/master/CONTRIBUTING.md)

## Learn more

This module doesn't support array uploads. For heavy duty, you'll probably have to work with [fs.readdir](https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback) and [async forEach](https://www.npmjs.com/package/async-foreach) (you may also be interested in [path](https://nodejs.org/api/path.html#path_path) ).

For example, you can create a `baseDir.js` file wherever it suits you:

```
// baseDir.js
const path = require('path');
const dirPath = path.join(__dirname);
module.exports = dirPath;
```

Then you can require this file elsewhere and use something like `path.join(myDirpath, "subfolder", subsubfolder)` to dig into directories programmatically. Once there, you can f.e. `fs.readdir` and iterate `forEach` file of that directory.  
See `fs` documentation and Stack Overflow for more inspiration on the matter.

[CHANGELOG](https://github.com/TheRealBarenziah/imgbb-uploader/blob/master/CHANGELOG.md)

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