You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
14
15
15
16
This SDK supports both CommonJS and ESM.
16
17
##### Table of contents
@@ -52,18 +53,23 @@ var imagekit = new ImageKit({
52
53
```
53
54
54
55
## 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.
56
57
57
58
## 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`
59
64
60
65
## URL Generation
61
66
62
67
**1. Using image path and image hostname or endpoint**
63
68
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.
65
70
66
71
```js
72
+
// For URL Generation, works for both images and videos
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.
86
92
87
93
88
94
```js
@@ -247,7 +253,7 @@ If you want to generate transformations in your application and add them to the
247
253
248
254
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).
249
255
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).
251
257
252
258
Sample usage
253
259
```js
@@ -288,7 +294,7 @@ imagekit.upload({
288
294
```
289
295
290
296
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.
292
298
293
299
294
300
@@ -298,7 +304,7 @@ The SDK provides a simple interface for all the [media APIs mentioned here](http
298
304
299
305
**List & Search Files**
300
306
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.
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).
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.
405
411
406
412
```js
407
413
// Using Callback Function
@@ -448,14 +454,14 @@ Add tags to multiple files in a single request as per [API documentation here](h
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).
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).
742
748
743
749
```js
744
750
// Using Callback Function
@@ -767,7 +773,7 @@ imagekit.copyFolder({
767
773
768
774
**Move Folder**
769
775
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).
771
777
772
778
```js
773
779
// Using Callback Function
@@ -794,7 +800,7 @@ imagekit.moveFolder({
794
800
795
801
**Get bulk job status**
796
802
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.
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.
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)
903
909
@@ -1043,7 +1049,7 @@ We have included the following commonly used utility functions in this package.
1043
1049
1044
1050
### Authentication parameter generation
1045
1051
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.
1047
1053
1048
1054
*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*
1049
1055
@@ -1064,9 +1070,9 @@ Both the `token` and `expire` parameters are optional. If not specified, the SDK
1064
1070
1065
1071
### Distance calculation between two pHash values
1066
1072
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.
1068
1074
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.
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.
1097
1103
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.
1099
1105
1100
1106
| Property | Description |
1101
1107
|----------|-------------|
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. |
1104
1110
|`X-RateLimit-Interval`| The duration of interval in milliseconds for which this rate limit was exceeded. |
0 commit comments