Node.js/Express – PostgreSQL example – Upload File/Download File – Multer + Sequelize CRUD
Tags: node, mysql, sequelize, crud
Published: 2021-05-12 11:04:25

https://grokonez.com/node-js/sequelize/node-js-express-rest-api-postgresql-example-upload-file-download-file-multer-sequelize-crud

Node.js/Express – PostgreSQL example – Upload File/Download File – Multer + Sequelize CRUD

In the tutorial, we show how to build a Node.js/Express RestAPIs to Upload Files/Download Files to PostgreSQL using Multer middleware and Sequelize ORM.

Related posts:
- <a href="https://grokonez.com/node-js/multer-build-restapi-to-upload-a-multipartfile-to-nodejs-express">Multer – Build RestAPI to upload a MultipartFile to NodeJS/Express</a>
- <a href="https://grokonez.com/node-js/nodejs-restapis-how-to-create-nodejs-express-restapis-post-get-put-delete-requests">NodeJs/Express RestAPIs – POST/GET/PUT/DELETE requests</a>

<!--more-->
<h2>Technologies</h2>
<ul>
<li>Node.js</li>
<li>Express</li>
<li>Multer</li>
<li>Sequelize</li>
<li>PostgreSQL</li>
</ul>
<h2>Goal</h2>
We create Node.js project as below:

<img src="https://grokonez.com/wp-content/uploads/2018/07/nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql-nodejs-project.png" alt="nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql + nodejs-project" width="344" height="350" class="alignnone size-full wp-image-13639" />

Expose 3 RestAPIs:

<ul>
<li><code>router.post('/api/file/upload', upload.single("file"), fileWorker.uploadFile);</code></li>
<li><code>router.get('/api/file/info', fileWorker.listAllFiles);</code></li>
<li><code>router.get('/api/file/:id', fileWorker.downloadFile);</code></li>
</ul>

Upload file:

<img src="https://grokonez.com/wp-content/uploads/2018/07/nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql-post-request-upload-file.png" alt="nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql + post-request-upload-file" width="539" height="360" class="alignnone size-full wp-image-13640" />

-> PostgreSQL's records:

<img src="https://grokonez.com/wp-content/uploads/2018/07/nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql-postgrsql-records.png" alt="nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql + postgrsql-records" width="675" height="230" class="alignnone size-full wp-image-13641" />

Download file:

<img src="https://grokonez.com/wp-content/uploads/2018/07/nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql-get-file.png" alt="nodejs-express-restapis-multer-upload-files-download-files-sequelize-postgresql + get-file" width="680" height="363" class="alignnone size-full wp-image-13642" />
<h2>Practice</h2>
<h3>Setting up NodeJs/Express project</h3>
Create a folder Node.js-Express-Upload-Download-Files-PostgreSQL:

<pre><code class="language-javascript">
mkdir Node.js-Express-Upload-Download-Files-PostgreSQL
cd Node.js-Express-Upload-Download-Files-PostgreSQL
</code></pre>

More:

https://grokonez.com/node-js/sequelize/node-js-express-rest-api-postgresql-example-upload-file-download-file-multer-sequelize-crud

Node.js/Express – PostgreSQL example – Upload File/Download File – Multer + Sequelize CRUD