Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
How to get an array of files in a directory

In PHP I have the following code to create an array of all images in a directory.

$dir    = '/public/images/';
$files = scandir($dir);

What would the NodeJS equivalent be?

I am looking to create an array of all images in a directory.

Using this in Laravel webpack mix in development so it would run either on the local machine or on the server itself by command line.

Instead of the following as there is an unknown number of images in the directory and what the name would be.

if (mix.config.inProduction) {
    mix.version(['public/images/50x50-1.png', 'public/images/50x50-1.svg'])
}

Desired Code:

if (mix.config.inProduction) {
    var imagesArray = // get the list here
    mix.version(imagesArray)
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If this is running on the server, you should have access to node's fs module.

const testFolder = '/public/images/';
const fs = require('fs');
fs.readdir(testFolder, (err, files) => {
  files.forEach(file => {
    console.log(file);
  });
})

You can read up on fs here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda