title: How to delete files with NodeJS?
body: <p>I have two async functions:</p>
  <ol>
  <li>One for creating objects in PostgreSQL and upload files with named in this object.</li>
  <li>Another one for deleting this entity and deleting files from folder.</li>
  </ol>
  <p><strong>I don't know how to extract filenames from PostgreSQL entity and delete certain files in my 'static' folder</strong></p>
  <p><strong>Entity in PostgreSQL looks like:</strong></p>
  <pre><code>Car:
    {
     'name': 'Nissan 350Z',
     'description': 'new',
     'image': '123wejdsefberfkj.jpg',
     'video': '23rusdjf8ioysdfs.mp4'
    }
  </code></pre>
  <p><strong>Create function:</strong></p>
  <p><em>Here I get files from form-data, create unique name for files and save it in PostgreSQL, then I  save files in &quot;static&quot; folder.</em></p>
  <pre><code> let videoName = uuid.v4() + '.mp4';
   let imageName = uuid.v4() + '.jpg';
   let {name,description} = req.body;
   const {video, image} = req.files; 
   const car = await Car.create( {name, description, video: videoName,image: imageName})
                  .then(video.mv(path.resolve(__dirname,'..', 'static', videoName)))
                  .then(image.mv(path.resolve(__dirname,'..', 'static', imgName)))
  </code></pre>
  <p><strong>Delete function:</strong></p>
  <p>Here I need to extract file-names from database and delete them from folder</p>
  <p><em>a bit pseudocode:</em></p>
  <pre><code>async delete(req, res) {
          try {
              const {id} = req.params;
              await Car.findOne({where:{id}})
                  .then( async data =&gt; {
                      if(data) {
                          await let videoName = Car.@extract_video_name@ ({where: {id}})
                                .then(mv(path.delete(__dirname,'..','static',videoName)))
                          await Car.destroy({where:{id}}).then(() =&gt; {
                              return res.json(&quot;Car deleted&quot;);
                          })
                      } else {
                          return res.json(&quot;This Car doesn't exist in database&quot;);
                      }
                  })
              
          } catch (e) {
              console.error(e)
          }
      }
  </code></pre>