Book Image

Mastering Web Application Development with Express

By : Alexandru Vladutu
Book Image

Mastering Web Application Development with Express

By: Alexandru Vladutu

Overview of this book

Table of Contents (18 chapters)
Mastering Web Application Development with Express
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling file uploads


A common thing that people sometimes forget when dealing with file uploads is to remove the temporary files after they're done with them.

Let's create an application that allows the user to upload an image and list its properties. We will first need to install the express, gm, connect-multiparty, and ejs modules, using the following command:

$ npm i express gm connect-multiparty ejs

Note

For the gm module to work properly, we also need to install GraphicsMagick and ImageMagick. For more details, check out the NPM page for the module at https://www.npmjs.org/package/gm.

First, let's create the home.html template file inside the /views folder, using the following code:

<!DOCTYPE HTML>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Uploading files</title>
</head>
<body>
  <h1>Upload file</h1>

  <form action="/files" method="POST" enctype="multipart/form-data">
    <div>
      <label for...