Socket
Socket
Sign inDemoInstall

imgbb-uploader

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    imgbb-uploader

Lightweight module to upload images through Imgbb API.


Version published
Weekly downloads
5.4K
increased by21.56%
Maintainers
1
Install size
16.9 kB
Created
Weekly downloads
 

Changelog

Source

1.1.0

Module overhaul:
Seeing some people found this module useful made me glad, so I decided to give it some love.

  • Becomes dependency-free
    The respectable request module was the only external dependency, but now that's unsupported, as npm install spams everytime, it's problematic.
    While I could have replaced it with Axios, I preferred reinventing that wheel using standard node https. It should hold for the years to come.

  • TypeScript support
    TypeScript is all the rage and I'm still in the process of learning it. That's why I thought it was interesting to make this module TS compatible, without breaking compatibility for the require(); users.

  • Better integration for VSCode
    I've discovered JSDoc since then. It should benefit even non-TypeScript users.

  • Change code style I have semi colons everywhere except in this little module. Fixed that. Long live semi colons :)

  • Upgraded file architecture & CI
    This is the resource that guided me through the TS/Jest stack, it was an interesting adventure.
    I made my best to ensure this update won't break anything for you, but if it is the case, please open an issue :)

Todo:
Write more in CONTRIBUTING.md so this module remains easy to fork & tweak. It may look more bloated than before, but I'm convinced decent documentation should fix it.

Making .mjs import work. Hopefully soon
Supporting browsers (afterall why not)
Supporting passing filename parameter
Supporting arrays (in the very bottom of the list tbh)

Readme

Source

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 code style: prettier Known Vulnerabilities Build Status

Compatibility:

Node >= 8 ( this module uses async/await )
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 instead

Install

npm install imgbb-uploader

Use

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

Learn more

This module doesn't support array uploads. For heavy duty, you'll probably have to work with fs.readdir and async forEach (you may also be interested in 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

Keywords

FAQs

Last updated on 17 Aug 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc