# express-easy-fileuploader

> easy express file uploader (laravel like)

Latest version **1.0.2** (published 2023-08-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install express-easy-fileuploader
pnpm add express-easy-fileuploader
yarn add express-easy-fileuploader
bun add express-easy-fileuploader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-08-05 |
| First published | 2023-08-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Abdullah Nouraldaim |
| Maintainers | abdullah1225 |
| Keywords | express-easy-fileuploader |

## Links

- npm: https://www.npmjs.com/package/express-easy-fileuploader
- Repository: https://github.com/abdullah1225/express-easy-fileuploader
- Homepage: https://github.com/abdullah1225/express-easy-fileuploader#readme
- Issues: https://github.com/abdullah1225/express-easy-fileuploader/issues
- npm.io page: https://npm.io/package/express-easy-fileuploader

## Dependencies (2)

- [express](https://npm.io/package/express.md) ^4.18.2
- [express-fileupload](https://npm.io/package/express-fileupload.md) ^1.4.0

## Recent versions

- 1.0.2 (latest) — 2023-08-05
- 1.0.1 — 2023-08-05
- 1.0.0 — 2023-08-04

## README

##  Express Easy File Uploader

the hardest part about express is handling file uploads. there are a lot of packages for this purpose but all of them add extra layer of difficulty. our package [express-easy-fileupload](https://github.com/abdullah1225/express-easy-fileuploader) uses the old package [express-fileupload](https://github.com/richardgirges/express-fileupload) and put a very powerful middleware to convert the manual code that the old library instruct you to write to a small function attached to the request object


## Features

1. Small function attached for each file separately (more flexibility)
2. Handles both single and multiple files
3. Can generate file name for the files if you want (optional)
4. Check file existence in desk
5. Can create the path of folder you pass to save the file if not exists (optional)


## Install

    npm i express-easy-fileupload


# Usage
## First of all you need to import the package and use add as middleware in your express app.

    const fileEasyUpload = require("express-easy-fileuploader")
    var app = express();
    app.use(  
       fileEasyUpload({  
          app,  
      fileUploadOptions:{  
          limits: { fileSize: 500 * 1024 * 1024 },  
      }  
       })  
    );

the middleware receives object containing the following:

- **`app`**: the express application instance
- **`fileUploadOptions`**: the old express-fileupload options (you can get it from [this link](https://www.npmjs.com/package/express-fileupload#available-options))

## Second you save the files in your express routes' handlers

you save the file by calling the method `save` on the file name in the request object. save receives 2 parameters
- **`directoryPath`**
- **`fileName`** : optional. the package can generate name for you (better not use it)

       app.post("/api/test",async function(req,res){  
	       var path1 = await req.photo.save(directoryPath)  
	       var path2 = await req.cv.save(directoryPath)  

	       var pathes = []  
	       for(var i=0;i<req.docs.length;i++){  
	          pathes.push(await req.docs[i].save(directoryPath))  
	       }  
	       console.log("photo is saved to",path1)  
	       console.log("cv is saved to",path2)  
	       console.log("docs are saved to",pathes)  
	      // the rest of your logic 
        });
where photo and cv are single files and docs is a multiple file
in HTML single files look like the following

    <input type='file' name='cv'>
    <input type='file' name='photo'>
and multiple files look like the following

    <input type='file' multiple name='docs'>

---
_Source: https://npm.io/package/express-easy-fileuploader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
