A
A
Anton2019-08-08 14:38:06
JavaScript
Anton, 2019-08-08 14:38:06

How to process a large number of files in javascript?

You need to process a large number of pictures that are in one folder.
I use the imagemin library and the code:

const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
(async () => {
  const files = await imagemin(['../imported/imported_fvalencia/*.{jpg,jpeg}'], {
    destination: 'build/images',
    plugins: [
      imageminMozjpeg({
        quality: 80
      })
    ]
  });

  //console.log(files);
  //=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
})();

Error after launch: (node:13184) UnhandledPromiseRejectionWarning: Error: EMFILE: too many open files, open
I suppose that it is possible to somehow limit the number of files or can somehow turn off asynchrony so that this error does not occur?
Friends, help with advice or a recipe. Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question