This is a starter CDN with Imagekit.io powered by Express
ImageKit Node.js SDK allows you to use image resizing, optimization, file uploading and other ImageKit APIs from applications written in server-side JavaScript.
- Clone this repo
- run
npm install
- run
npm run dev
for development - run
npm start
for production
- rename
nodemon.example.json
tonodemon.json
- edit with your imagekit.io key
{
"env": {
"IMAGEKIT_URL_ENDPOINT": "YOUR_IMAGEKIT_URL_ENDPOINT",
"IMAGEKIT_PUBLIC_KEY": "YOUR_IMAGEKIT_PUBLIC_KEY",
"IMAGEKIT_PRIVATE_KEY": "YOUR_IMAGEKIT_PRIVATE_KEY"
}
}
form action="#" onsubmit="upload()">
<input type="file" id="file1" />
<input type="submit" />
</form>
<script type="text/javascript" src="../dist/imagekit.js"></script>
<script>
/*
SDK initilization
authenticationEndpoint should be implemented on your server
as shown above
*/
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id",
authenticationEndpoint : "https://www.yourserver.com/auth"
});
// Upload function internally uses the ImageKit.io javascript SDK
function upload(data) {
var file = document.getElementById("file1");
imagekit.upload({
file : file.files[0],
fileName : "abc.jpg",
tags : ["tag1"]
}, function(err, result) {
console.log(arguments);
console.log(imagekit.url({
src: result.url,
transformation : [{ height: 300, width: 400}]
}));
})
}
</script>