Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Get all images exif and pass to route as object

how to get all Images exif and pass it to view in Expressjs

basically it has to wait for 2 promisses

get filnames with readdir and get exifs and return as array to view

here what I have but lost.

const express = require('express');
const exifr = require('exifr');
const fs = require('fs');
const fsPromises = fs.promises;

const app = express();
 
app.set('view engine', 'ejs')

let defaultOptions = {
// Segments (JPEG APP Segment, PNG Chunks, HEIC Boxes, etc...)
tiff: false,
xmp: false,
icc: false,
iptc: true,
jfif: false, // (jpeg only)
ihdr: false, // (png only)
// Sub-blocks inside TIFF segment
ifd0: false, // aka image
ifd1: false, // aka thumbnail
exif: false,
gps: true, 
}
 

const photosDir = './photos/'
 
 
app.use('/photos', express.static('photos'))
async function listDir() {
  try {
    return fsPromises.readdir(photosDir) .then(filenames => {
      for (let filename of filenames) {
          //console.log(filename)
            exifr.parse(photosDir+filename, defaultOptions).then(function(data){
              console.log(data)
              return data
            })
      }
  });
  } catch (err) {
    console.error('Error occured while reading directory!', err);
  }
}
listDir()
 
app.get('/', async (_,res) => {

 let data =  await listDir() 
console.log(data)
  res.render('index',{"files":  data })
});

app.listen(3000, () => console.log('Example app is listening on port 3000.'));

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use Promise.all, this will resolve after all exifr.parse promises have resolved.

return fsPromises.readdir(photosDir)
.then(filenames => Promise.all(filenames.map(filename =>
  exifr.parse(photosDir+filename, defaultOptions)
  .then(function(data) {
    console.log(data)
    return data
  })
)));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!