Better Programming

Advice for programmers.

Follow publication

Member-only story

Handling File Uploads With NestJS and MySQL

Arctype
Better Programming
Published in
7 min readAug 3, 2022
Handling File Uploads with NestJS and MySQL

Introduction

Many developers despise dealing with file uploads. This can be attributed to a lack of knowledge about the best approach to take or difficulties determining how to configure their Nest.js application to handle file uploads. Many people may want to save their files directly to a MySQL database, or save image names and have the image saved on disk storage: it all depends on their preferences and the goals they want to achieve. This tutorial will teach you how to build a file uploading functionality using Nestjs and MySQL.

Prerequisites

Before you begin following this tutorial, ensure your system meets the following requirements:

Setting Up NestJS

Once the above-mentioned requirements are met, proceed to install the Nestjs CLI and create a new project by running the following commands:

$ npm i -g @nestjs/cli
$ nest new file-upload

These commands will install the Nestjs CLI and create a new Nestjs project with the folder structure below.

📦file-upload
┣ 📂src
┃ ┣ 📜app.controller.spec.ts
┃ ┣ 📜app.controller.ts
┃ ┣ 📜app.module.ts
┃ ┣ 📜app.service.ts
┃ ┣ 📜image.entity.ts
┃ ┗ 📜main.ts
┣ 📂test
┃ ┣ 📜app.e2e-spec.ts
┃ ┗ 📜jest-e2e.json
┣ 📜.eslintrc.js
┣ 📜.gitignore
┣ 📜.prettierrc
┣ 📜README.md
┣ 📜nest-cli.json
┣ 📜package-lock.json
┣ 📜package.json
┣ 📜tsconfig.build.json
┗ 📜tsconfig.json

After the Nestjs project has been created, move on to the next step — install the required dependencies for your application by running the following command:

npm install --save @nestjs/typeorm typeorm mysql2

In the above command, you’ve installed the TypeORM and mysql2 modules: they will enable you to connect your application to a MySQL database and perform operations on…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Arctype
Arctype

Written by Arctype

The modern SQL editor built for collaboration www.arctype.com

Responses (1)

Write a response