Skip to content

Commit 75d98ba

Browse files
committed
docs update
1 parent 64edbc5 commit 75d98ba

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

README.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
[<img width="250" alt="ImageKit.io" src="https://raw.githubusercontent.com/imagekit-developer/imagekit-javascript/master/assets/imagekit-light-logo.svg"/>](https://imagekit.io)
32

43
# ImageKit.io Node.js SDK
@@ -10,7 +9,9 @@
109
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1110
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
1211

13-
ImageKit Node.js SDK allows you to use [image resizing](https://docs.imagekit.io/features/image-transformations), [optimization](https://docs.imagekit.io/features/image-optimization), [file uploading](https://docs.imagekit.io/api-reference/upload-file-api) and other [ImageKit APIs](https://docs.imagekit.io/api-reference/api-introduction) from applications written in server-side JavaScript.
12+
Node.js SDK for [ImageKit](https://imagekit.io/) implements the new APIs and interface for different file operations.
13+
14+
ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
1415

1516
This SDK supports both CommonJS and ESM.
1617
##### Table of contents
@@ -52,18 +53,23 @@ var imagekit = new ImageKit({
5253
```
5354

5455
## Demo application
55-
The fastest way to get started is by running the demo application in [sample](/sample) folder. Refer to the README file in [sample](/sample) folder.
56+
The fastest way to get started is by running the demo application in the [sample](/sample) folder. Refer to the README file in [sample](/sample) folder.
5657

5758
## Usage
58-
You can use this NodeJS SDK for three different kinds of functions - URL generation, file uploads, and file management. The usage of the SDK has been explained below.
59+
You can use this Node.js SDK for three different methods - URL generation, file upload, and media management operations. The usage of the SDK has been explained below.
60+
61+
* `URL Generation`
62+
* `File Upload`
63+
* `File Management`
5964

6065
## URL Generation
6166

6267
**1. Using image path and image hostname or endpoint**
6368

64-
This method allows you to create a URL using the `path` where the image exists and the URL endpoint (`urlEndpoint`) you want to use to access the image. You can refer to the documentation [here](https://docs.imagekit.io/integration/url-endpoints) to read more about URL endpoints in ImageKit and the section about [image origins](https://docs.imagekit.io/integration/configure-origin) to understand about paths with different kinds of origins.
69+
This method allows you to create an URL to access a file using the relative file path and the ImageKit URL endpoint (`urlEndpoint`). The file can be an image, video or any other static file supported by ImageKit.
6570

6671
```js
72+
// For URL Generation, works for both images and videos
6773
var imageURL = imagekit.url({
6874
path : "/default-image.jpg",
6975
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/endpoint/",
@@ -82,7 +88,7 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jp
8288

8389
**2. Using full image URL**
8490

85-
This method allows you to add transformation parameters to an existing, complete URL that is already mapped to ImageKit using the `src` parameter. Use this method if you have the absolute image URL stored in your database.
91+
This method allows you to add transformation parameters to an absolute URL. For example, if you have configured a custom CNAME and have absolute asset URLs in your database or CMS, you will often need this.
8692

8793

8894
```js
@@ -247,7 +253,7 @@ If you want to generate transformations in your application and add them to the
247253

248254
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media Library. It accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
249255

250-
The `upload()` method requires at least the `file` and the `fileName` parameter to upload a file and returns a callback with the `error` and `result` as arguments. You can pass other parameters supported by the ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to specify tags for a file at the time of upload, use the `tags` parameter as specified in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
256+
The `upload()` method requires at least the `file` and the `fileName` parameter to upload a file and returns a callback with the `error` and `result` as arguments. You can pass other parameters supported by the ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to set tags for a file at the upload time, use the `tags` parameter as defined in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
251257

252258
Sample usage
253259
```js
@@ -288,7 +294,7 @@ imagekit.upload({
288294
```
289295

290296
If the upload succeeds, `error` will be `null,` and the `result` will be the same as what is received from ImageKit's servers.
291-
If the upload fails, `error` will be the same as what is received from ImageKit's servers, and the `result` will be null.
297+
If the upload fails, the `error` will be the same as what is received from ImageKit's servers, and the `result` will be null.
292298

293299

294300

@@ -298,7 +304,7 @@ The SDK provides a simple interface for all the [media APIs mentioned here](http
298304

299305
**List & Search Files**
300306

301-
Accepts an object specifying the parameters to be used to list and search files. All parameters specified in the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files) can be passed as-is with the correct values to get the results.
307+
Accepts an object specifying the parameters used to list and search files. All parameters specified in the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files) can be passed as-is with the correct values to get the results.
302308

303309
```js
304310
// Using Callback Function
@@ -372,7 +378,7 @@ imagekit.getFileVersions("file_id")
372378

373379
**Get File version details**
374380

375-
Accepts the file ID and version ID, returns the details of that specific version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details).
381+
Accepts the file ID & version ID and returns the details of that specific version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details).
376382

377383
```js
378384
// Using Callback Function
@@ -401,7 +407,7 @@ imagekit.getFileVersionDetails({
401407

402408
**Update File Details**
403409

404-
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details). The first argument to the `updateFileDetails` method is the file ID, and a second argument is an object with the parameters to be updated.
410+
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details). The first argument to the `updateFileDetails` method is the file ID, and the second argument is an object with the parameters to be updated.
405411

406412
```js
407413
// Using Callback Function
@@ -448,14 +454,14 @@ Add tags to multiple files in a single request as per [API documentation here](h
448454
```js
449455
// Using Callback Function
450456

451-
imagekit.bulkAddTags(["fileIds"], ["tags"], function(error, result) {
457+
imagekit.bulkAddTags(["file_id_1", "file_id_2"], ["tag1", "tag2"], function(error, result) {
452458
if(error) console.log(error);
453459
else console.log(result);
454460
});
455461

456462
// Using Promises
457463

458-
imagekit.bulkAddTags(["fileIds"], ["tags"]).then(response => {
464+
imagekit.bulkAddTags(["file_id_1", "file_id_2"], ["tag1", "tag2"]).then(response => {
459465
console.log(response);
460466
}).catch(error => {
461467
console.log(error);
@@ -469,14 +475,14 @@ Remove tags from multiple files in a single request as per [API documentation he
469475
```js
470476
// Using Callback Function
471477

472-
imagekit.bulkRemoveTags(["fileIds"], ["tags"], function(error, result) {
478+
imagekit.bulkRemoveTags(["file_id_1", "file_id_2"], ["tags"], function(error, result) {
473479
if(error) console.log(error);
474480
else console.log(result);
475481
});
476482

477483
// Using Promises
478484

479-
imagekit.bulkRemoveTags(["fileIds"], ["tags"]).then(response => {
485+
imagekit.bulkRemoveTags(["file_id_1", "file_id_2"], ["tags"]).then(response => {
480486
console.log(response);
481487
}).catch(error => {
482488
console.log(error);
@@ -490,14 +496,14 @@ Remove AI tags from multiple files in a single request as per [API documentation
490496
```js
491497
// Using Callback Function
492498

493-
imagekit.bulkRemoveAITags(["fileIds"], ["ai-tag1", "ai-tag2"], function(error, result) {
499+
imagekit.bulkRemoveAITags(["file_id_1", "file_id_2"], ["ai-tag1", "ai-tag2"], function(error, result) {
494500
if(error) console.log(error);
495501
else console.log(result);
496502
});
497503

498504
// Using Promises
499505

500-
imagekit.bulkRemoveAITags(["fileIds"], ["ai-tag1", "ai-tag2"]).then(response => {
506+
imagekit.bulkRemoveAITags(["file_id_1", "file_id_2"], ["ai-tag1", "ai-tag2"]).then(response => {
501507
console.log(response);
502508
}).catch(error => {
503509
console.log(error);
@@ -561,15 +567,15 @@ Delete multiple files as per the [API documentation here](https://docs.imagekit.
561567
```js
562568
// Using Callback Function
563569

564-
imagekit.bulkDeleteFiles(["fileId1", "fileId2"], function(error, result) {
570+
imagekit.bulkDeleteFiles(["file_id_1", "file_id_2"], function(error, result) {
565571
if(error) console.log(error);
566572
else console.log(result);
567573
});
568574

569575

570576
// Using Promises
571577

572-
imagekit.bulkDeleteFiles(["fileId1", "fileId2"]).then(response => {
578+
imagekit.bulkDeleteFiles(["file_id_1", "file_id_2"]).then(response => {
573579
console.log(response);
574580
}).catch(error => {
575581
console.log(error);
@@ -717,7 +723,7 @@ imagekit.createFolder({
717723

718724
**Delete Folder**
719725

720-
This will delete the specified folder and all nested files & folders as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder).
726+
This will delete the specified Folder and all nested files & folders as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder).
721727

722728
```js
723729
// Using Callback Function
@@ -738,7 +744,7 @@ imagekit.deleteFolder("folderPath").then(response => {
738744

739745
**Copy Folder**
740746

741-
This will copy one folder into another as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder).
747+
This will copy one Folder into another as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder).
742748

743749
```js
744750
// Using Callback Function
@@ -767,7 +773,7 @@ imagekit.copyFolder({
767773

768774
**Move Folder**
769775

770-
This will move one folder into another as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder).
776+
This will move one Folder into another as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder).
771777

772778
```js
773779
// Using Callback Function
@@ -794,7 +800,7 @@ imagekit.moveFolder({
794800

795801
**Get bulk job status**
796802

797-
This allows us to get a bulk operation status e.g. copy or move folder as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status). This method accepts `jobId` that is returned by copy and move folder operations.
803+
This allows us to get a bulk operation status e.g. copy or move Folder as per [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status). This method accepts `jobId` that is returned by copy and move folder operations.
798804

799805
```js
800806
// Using Callback Function
@@ -815,7 +821,7 @@ imagekit.getBulkJobStatus("jobId").then(response => {
815821

816822
**Purge Cache**
817823

818-
Programmatically issue a cache clear request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache). Accepts the full URL of the file for which the cache has to be cleared.
824+
Programmatically issue a clear cache request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache). Accepts the full URL of the file for which the cache has to be cleared.
819825

820826
```js
821827
// Using Callback Function
@@ -897,7 +903,7 @@ imagekit.getFileMetadata("https://ik.imagekit.io/your_imagekit_id/sample.jpg")
897903
});
898904
```
899905

900-
**Create custom metadata field**
906+
**Create a custom metadata field**
901907

902908
Create a new custom metadata field as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
903909

@@ -1043,7 +1049,7 @@ We have included the following commonly used utility functions in this package.
10431049

10441050
### Authentication parameter generation
10451051

1046-
In case you are looking to implement client-side file upload, you are going to need a token, expiry timestamp, and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these authentication parameters for you.
1052+
If you want to implement client-side file upload, you will need a token, expiry timestamp, and a valid signature for that upload. The SDK provides a simple method you can use in your backend code to generate these authentication parameters.
10471053

10481054
*Note: The Private API Key should never be exposed in any client-side code. You must always generate these authentication parameters on the server-side*
10491055

@@ -1064,9 +1070,9 @@ Both the `token` and `expire` parameters are optional. If not specified, the SDK
10641070

10651071
### Distance calculation between two pHash values
10661072

1067-
Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on an image's contents. [ImageKit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash value of an image in the response. You can use this value to [find a duplicate (or similar) image](https://docs.imagekit.io/api-reference/metadata-api#using-phash-to-find-similar-or-duplicate-images) by calculating the distance between the two images' pHash value.
1073+
Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on an image's contents. For example, [ImageKit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash value of an image in the response. You can use this value to [find a duplicate (or similar) image](https://docs.imagekit.io/api-reference/metadata-api#using-phash-to-find-similar-or-duplicate-images) by calculating the distance between the two images' pHash value.
10681074

1069-
This SDK exposes `pHashDistance` function to calculate the distance between two pHash values. It accepts two pHash hexadecimal strings and returns a numeric value indicative of the level of difference between the two images.
1075+
This SDK exposes the `pHashDistance` function to calculate the distance between two pHash values. It accepts two pHash hexadecimal strings and returns a numeric value indicative of the level of difference between the two images.
10701076

10711077
```js
10721078
const calculateDistance = () => {
@@ -1093,14 +1099,14 @@ imagekit.pHashDistance('a4a65595ac94518b', '7838873e791f8400');
10931099
```
10941100

10951101
## Rate limits
1096-
Except for upload API, all [ImageKit APIs are rate limited](https://docs.imagekit.io/api-reference/api-introduction/rate-limits) to protect the infrastructure from excessive request rates and to keep ImageKit.io fast and stable for everyone.
1102+
Except for upload API, all [ImageKit APIs are rate limited](https://docs.imagekit.io/api-reference/api-introduction/rate-limits) to protect the infrastructure from excessive requests rates and to keep ImageKit.io fast and stable for everyone.
10971103

1098-
When you exceed the rate limits for an endpoint, you will receive a `429` status code. The Node.js library reads the [rate limiting response headers](https://docs.imagekit.io/api-reference/api-introduction/rate-limits#response-headers-to-understand-rate-limits) provided in API response and adds these in the error argument of callback or `.catch` when using promises. Please sleep/pause for the number of milliseconds specified by the value of `X-RateLimit-Reset` property before making additional requests to that endpoint.
1104+
When you exceed the rate limits for an endpoint, you will receive a `429` status code. The Node.js library reads the [rate limiting response headers](https://docs.imagekit.io/api-reference/api-introduction/rate-limits#response-headers-to-understand-rate-limits) provided in the API response and adds these in the error argument of the callback or `.catch` when using promises. Please sleep/pause for the number of milliseconds specified by the value of the `X-RateLimit-Reset` property before making additional requests to that endpoint.
10991105

11001106
| Property | Description |
11011107
|----------|-------------|
1102-
| `X-RateLimit-Limit` | The maximum number of requests that can be made to this endpoint in interval specified by `X-RateLimit-Interval` response header. |
1103-
| `X-RateLimit-Reset` | The amount of time in milliseconds, before you can make another request to this endpoint. Pause/sleep your workflow for this duration. |
1108+
| `X-RateLimit-Limit` | The maximum number of requests that can be made to this endpoint in the interval specified by the `X-RateLimit-Interval` response header. |
1109+
| `X-RateLimit-Reset` | The amount of time in milliseconds before you can make another request to this endpoint. Pause/sleep your workflow for this duration. |
11041110
| `X-RateLimit-Interval` | The duration of interval in milliseconds for which this rate limit was exceeded. |
11051111

11061112
## Support

0 commit comments

Comments
 (0)