imgbb-uploader
Advanced tools
Comparing version 0.1.2 to 1.0.0
16
index.js
@@ -1,6 +0,6 @@ | ||
var fs = require('fs'); | ||
var request = require('request'); | ||
const fs = require('fs'); | ||
const request = require('request'); | ||
var imgbbUploader = async function(apiKey, pathToFile){ | ||
var formData = { | ||
const imgbbUploader = async (apiKey, pathToFile) => { | ||
let formData = { | ||
image : fs.createReadStream(pathToFile) | ||
@@ -13,5 +13,5 @@ } | ||
}, | ||
function cb(err, httpResponse, body) { | ||
(err, httpResponse, body) => { | ||
if (err) { | ||
console.error('Upload failed:', err) | ||
console.error('Upload failed:\n', err) | ||
reject(err); | ||
@@ -24,3 +24,3 @@ } | ||
async function uploadToImgbb(apiKey, pathToFile){ | ||
const uploadToImgbb = async (apiKey, pathToFile) => { | ||
const result = await imgbbUploader(apiKey, pathToFile); | ||
@@ -30,2 +30,2 @@ return JSON.parse(result).data; | ||
module.exports = uploadToImgbb; | ||
module.exports = uploadToImgbb; |
{ | ||
"name": "imgbb-uploader", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Lightweight module to upload images through Imgbb API.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# imgbb-uploader | ||
### Lightweight nodejs module to easily upload images through imgbb API | ||
Lightweight Nodejs module to upload local pictures files to imgbb API and get display URLs in response. | ||
## Compatibility: | ||
Node >= 8 recommended ( [this module uses async/await](https://node.green/) ) | ||
Node >= 8 ( [this module uses async/await](https://node.green/) ) | ||
<<<<<<< HEAD | ||
*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* | ||
======= | ||
>>>>>>> b4a3e033c2a8543aaf1caa68e6bad19201048326 | ||
@@ -12,4 +16,4 @@ ## Install | ||
- I) [Get a free API key from imgbb](https://api.imgbb.com/) ( estimated time : ~1 minute ) | ||
- II) (facultative) [Put that key in an environment variable](https://www.npmjs.com/package/dotenv) | ||
- III) **imgbbUploader takes *exactly two* String arguments** : your API key, then the absolute path of your image : | ||
- 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 : | ||
@@ -21,3 +25,3 @@ ``` | ||
.then(response => console.log(response)) | ||
.catch(error => console.log(error)) | ||
.catch(error => console.error(1)) | ||
``` | ||
@@ -54,9 +58,9 @@ | ||
This function returns a promise, this is why : | ||
`console.log(imgbbUploader(myKey, myPath)) // output : Promise { <pending> }` | ||
Your data is available in the `.then(response => response)` as shown above. | ||
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. | ||
## Learn more | ||
This module doesn't support array uploads and other fancy stuff. For heavy duty uploads, you'll probably have to work with [fs.readdir](https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback) and [forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) methods ; in that case you may also be interested in [path](https://nodejs.org/api/path.html#path_path). | ||
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) ). | ||
@@ -70,5 +74,8 @@ For example, you can create a `baseDir.js` file wherever it suits you: | ||
``` | ||
Then you can require this file elsewhere, and use something like `path.join(myDirpath, "subfolder", "subsubfolder")` to dig into directories programmatically. Once you're there you can `fs.readdir` and iterate `forEach` file of that directory, then do whatever you want. | ||
That is just a simple example, see `fs` documentation and Stack Overflow for more inspiration. | ||
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. | ||
### Anyway, this module is ~20 lines long & totally unlicensed, so even the most junior Nodejs dev should be able to easily adapt it to its needs. | ||
### This module is ~20 lines long & totally unlicensed, so you can easily edit it to fit your need. | ||
## Changelog | ||
0.2.1 => 1.0.0 (Replace `var` and `function` with proper ES6 syntax & update README) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5670
0
78
24