Create your own image cdn

Abdelrahman Mohamed
Nov 4 · 1 min read

Node.js is one of most common languages last year, by Node.js you can create website, webservices and enterprise application.

This post helps you to create your own cdn for images.

  1. To install expressjs package to serve your images, run this command :-

npm i express — save

2. Install jimp package to make processing on images :-

npm i jimp — save

3. Install dotenv package to manage enviroment variables :-

npm i dotenv — save

4. Install cors package to allow or deny your images for displaying on other sites

npm i cors — save

After installing required packages create index.js.

Load required packages

Create instance of exprees

Use cors middleware to allow/disallow other sites to display your images

Use custom error handler

Handle all request to manage and display your images

Listen your app at PORT in .env file

To serve your application, run this command :-

node index.js

Full source code on github

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade