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

184
Views
Nodejs how to read directory and grab certain files

in my Nodejs project, i have a folder named input that contains green-1.png, green-2.png, green-3.png,red-1.png, red-2.png, red-3.png files

i want to read the input directory and grab only the all the green files.

i tried this code :

 const { promisify } = require('util')

 const readdir = promisify(fs.readdir)

 const files = await readdir('../input')

it works fine but it gets me all green and red files from input folder.

how can i get only all the green ones?

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

0

fs.readdir will get all the contents of a folder. There is no way to filter the files in the function.

The best you can do is filter the files to those that are green

const filteredFiles = files.filter((f) => f.includes('green'));
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!