M
M
marink02018-04-05 19:38:47
JavaScript
marink0, 2018-04-05 19:38:47

How to check if a directory exists, and if not, create it using multer?

Used to upload files multer.

const storage = multer.diskStorage({
  destination: 'uploads',
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now())
  }
})

The problem is that you 'uploads'have to create with pens, because it multersays
You are responsible for creating the directory when providing destination as a function. When passing a string, multer will make sure that the directory is created for you.

How can I make it check for the existence of this directory and create it if it doesn't exist?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2018-04-05
@marink0

https://nodejs.org/api/fs.html#fs_fs_exists_path_c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question