Skip to content

Commit 5d457f0

Browse files
committed
sapmple application readme update
1 parent bc8ab0b commit 5d457f0

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

README.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,41 @@
77

88
Javascript SDK for [ImageKit.io](https://imagekit.io) that implements the client-side upload and URL generation for use in the browser.
99

10-
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. 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.
10+
ImageKit is a complete image optimization and transformation solution with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names. It allows you to deliver optimized images in minutes with minimal code changes.
1111

1212
This SDK has no dependency.
1313

1414
## Installation
1515

16-
Download the `imagekit.js` file from the dist directory or using the following command. Use the optional `--save` parameter if you wish to save the dependency in your `package.json` file.
17-
16+
### Using npm
17+
Install `imagekit-javascript`
1818
```
1919
npm install imagekit-javascript
2020
```
2121

22-
Load it using a `<script>` tag.
22+
Now import ImageKit
23+
```js
24+
import ImageKit from "imagekit-javascript"
25+
26+
// or
27+
const ImageKit = require("imagekit-javascript")
28+
```
29+
30+
### Using CDN
31+
You can download a specific version of this SDK from a global CDN.
32+
```
33+
https://unpkg.com/[email protected]/dist/imagekit.min.js
34+
```
2335

36+
For latest version remove the version number i.e.
2437
```
25-
<script type="text/javascript" src="imagekit.js"></script>
38+
https://unpkg.com/imagekit-javascript/dist/imagekit.min.js
39+
```
40+
41+
Now load it using a `<script>` tag.
42+
43+
```
44+
<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/imagekit.min.js"></script>
2645
```
2746

2847
## Initialization
@@ -40,8 +59,25 @@ var imagekit = new ImageKit({
4059

4160
*Note: Do not include your Private Key in any client-side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error*
4261

43-
## Usage
62+
## Demo Application
63+
64+
The fastest way to get started is by running the demo application. You can run the code locally. The source code is in [samples/sample-app](https://github.com/imagekit-developer/imagekit-javascript/tree/master/samples/sample-app).
65+
66+
To run it:
67+
68+
```
69+
git clone https://github.com/imagekit-developer/imagekit-javascript.git
70+
71+
cd imagekit-javascript
72+
```
73+
74+
Create a file `.env` using `sample.env` in the directory `samples/sample-app` and fill in your `PRIVATE_KEY`, `PUBLIC_KEY` and `URL_ENDPOINT` from your [imageKit dashboard](https://imagekit.io/dashboard#developers). The just run:
4475

76+
```
77+
yarn startSampleApp
78+
```
79+
80+
## Usage
4581
You can use this SDK for URL generation and client-side file uploads.
4682

4783
### URL Generation
@@ -241,22 +277,3 @@ Sample usage
241277
If the upload succeeds, `err` will be `null`, and the `result` will be the same as what is received from ImageKit's servers.
242278
If the upload fails, `err` will be the same as what is received from ImageKit's servers, and the `result` will be null.
243279

244-
245-
### Demo Application
246-
247-
The fastest way to get started is by running the demo application. You can run the code locally. The source code is in [samples/sample-app](https://github.com/imagekit-developer/imagekit-javascript/tree/master/samples/sample-app).
248-
249-
To run it:
250-
251-
```
252-
git clone https://github.com/imagekit-developer/imagekit-javascript.git
253-
254-
cd imagekit-javascript
255-
```
256-
257-
Create a file `.env` in the directory `samples/sample-app` and fill in your `PRIVATE_KEY`, `PUBLIC_KEY` and `URL_ENDPOINT` from your [imageKit dashboard](https://imagekit.io/dashboard#developers). The just run:
258-
259-
```
260-
yarn startSampleApp
261-
```
262-

samples/sample-app/server/server.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const fs = require('fs');
77
const path = require('path');
88

99
const pugTemplatePath = path.join(__dirname, "../views/index.pug");
10-
const js = fs.readFileSync(path.join(__dirname, "../../../dist/imagekit.min.js"));
1110

1211
const app = express();
1312
app.use(cors());
@@ -48,16 +47,6 @@ const startServer = (port = 3000, PUBLIC_KEY, PRIVATE_KEY, URL_ENDPOINT) => {
4847
}
4948
});
5049

51-
router.get("/imagekit.js", (req, res) => {
52-
try {
53-
res.set('Content-Type', 'text/javascript');
54-
res.send(Buffer.from(js));
55-
} catch (err) {
56-
console.error("Error while responding to static page request:", JSON.stringify(err, undefined, 2));
57-
res.status(500).send("Internal Server Error");
58-
}
59-
});
60-
6150
router.get("/", (req, res) => {
6251
try {
6352
res.render(pugTemplatePath, {publicKey: PUBLIC_KEY, urlEndpoint: URL_ENDPOINT, authenticationEndpoint: `http://localhost:3000/auth`});
@@ -67,10 +56,6 @@ const startServer = (port = 3000, PUBLIC_KEY, PRIVATE_KEY, URL_ENDPOINT) => {
6756
}
6857
});
6958

70-
71-
72-
73-
7459
app.use("/",router);
7560

7661
app.listen(port, () => {

samples/sample-app/views/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ html
1818
p
1919
img(src="")
2020

21-
script(type='text/javascript' src="/imagekit.js")
21+
script(type='text/javascript' src="https://unpkg.com/imagekit-javascript/dist/imagekit.min.js")
2222
script.
2323
try {
2424
var imagekit = new ImageKit({

0 commit comments

Comments
 (0)