Upload and Store Images in MySQL using Node.Js, Express, Express-FileUpload & Express-Handlebars
Today we are going to explore the Express-FileUpload NPM package as we create a super simple user profile card and integrate our card with a MySQL database to retain the record.
If you are looking for a in depth explanation please watch the full video tutorial.
What you need:
To complete this project you will need a MySQL Database & Node installed. I usually use XAMPP for local development, but you can use whatever you wish as long as the database is MySQL of course.
Create a new project
To create a new Node.js project all you have to do is to create a new project folder “user-management-system” and then run the Command line or PowerShell in the same directory. Once you do that to initialise a new project simply put the following command:
This will initialise a new project for you and it’s going to ask you a few questions about your project. The most important one is to give your package a name and then you can just keep pressing enter until the installation is over.
Let’s create the following folders and files, leaving node_modules, readme.md, package-lock and package-json as that should have been automatically generated by now.
You can structure your project the way you like. I am just going to keep it simple and add everything into our app.js file
📂 node_modules 📂 public 📂 css 📜 main.css 📜 main.scss 📂 img 🖼 default.jpg 📜 README.md ⚓ .env 🌍 app.js 📜 package-lock.json 📜 package-json
Let’s create our app.js file and each block of code will be explained with comments.
That’s it. The clean code is available on the GitHub link below with less explanation comments.
Thank you for reading this article. Please consider subscribing to my YouTube Channel.