Node.js Express Convert PNG JPG Images to Single PDF File Web App Using ImageMagick Library Deployed to Heroku 2020

You are currently viewing Node.js Express Convert PNG JPG Images to Single PDF File Web App Using ImageMagick Library Deployed to Heroku 2020





Live Demo


You can see the live demo of the app right here


Get Started


In order to get started you need to install these dependencies which are listed below


npm init -y


npm i express


npm i multer


npm i nodemon



Now make the entry level file index.js and start a simple express server on port 3000 like this





Now we will load the index.html for our user so that it can interact with the application. Copy paste the code inside the index.html file









Creating Uploads Folder Dynamically



Now we will create the folders dynamically where we will store the mp3 files which will be processed by imagemagick and then it will be converted to a pitched file






Here for the very first time the node.js application loads it will check the condition if the folder public doesn’t exist then it will create this folder and also it will create the uploads folder inside the public folder as a subdirectory.




Setting Public Folder as Static



Now in this block of code we will set the public folder as static so that it can store the mp3 files






Loading the BodyParser Middleware



BodyParser middleware is very much necessary for this application as we will processing the form data which is submitted by the user inside the index.html file. So for that you need to copy paste the below code inside index.js






Uploading Image Files to Server Using Multer



Now the comes the most important part of the application we need to first of all upload the images to the uploads folder before we can process them. So for this we will be using a famous library of node called multer to do this task. Copy paste this block of code to upload files inside node.





Converting Image Files to Single PDF File



Now we will do the fun part of the application after we upload the images files on the server. We will issue a simple shell command inside our node.js application using a built in library of node called as child_process. So in this block of code we will use a special imagemagick command which will carry out this process for us automatically. All this code will be put inside the post request which the user makes inside the index.html form.






Deploy to Heroku



Watch the youtube video given above for this task and here you need this url which is given below to add a buildback inside heroku project to install imagemagick inside your project.











Leave a Reply