Create your own image cdn
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.
- 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