Node JS – Auto Generate a Photo Gallery from a Directory

In my previous articles, I wrote tutorial on this topic but it was in PHP, in this post I would like to show you, how you can generate a photo gallery based on the images within given directory using Node js as a platform, express js as framework.

I am not going to write about express js or node js here, as that topics are out of scope for this tutorial, lets focus on topic directly, if you need more information on node js and express js please feel free to visit – https://nodejs.org/, https://expressjs.com/

This project is simple. We will use express web server which does the task of routing and html generation with pug template engine.

Installing dependencies

Save the above json string in the package.json file, and from that folder, open your terminal and type

With issuing above command, node package manager will pull all the required dependencies into node_modules folder under your project root folder.

Create a file called server.js, you can name it as you wish but make sure to update package.json file.

Here is my view file, which using pug template engine.

Running Project

Just issue following command form the terminal, but before doing that please update folder name and path from where you want to pull images.

Now point your to http://localhost:8080/get-images, you will get output similar to below,

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.