multer-upload-helper
v1.0.1
Published
multer file upload middleware for Node.js and Express apps
Maintainers
Readme
multer-upload-helper
A lightweight and reusable middleware for file uploading using multer. Easily integrate file upload with custom options in Express applications.
✨ Features
- Set custom upload directory
- Restrict file types (e.g., images, PDFs)
- Set max file size
- Automatically ensures upload folder exists
📦 Installation
npm install multer-upload-helper
## 🚀 Usage
```js
const express = require("express");
const uploadFile = require("multer-upload-helper");
const app = express();
const upload = uploadFile({
destination: "uploads/",
maxSize: 2 * 1024 * 1024, // 2MB
allowedTypes: /jpeg|jpg|png|pdf/
});
app.post("/upload", upload.single("file"), (req, res) => {
res.send("File uploaded successfully!");
});
app.listen(3000, () => {
console.log("Server started on port 3000");
});
## ⚙️ Options
| Option | Type | Default | Description |
|---------------|----------|-------------------|--------------------------------------------|
| `destination` | `string` | `'upload/'` | Folder where files will be saved |
| `maxSize` | `number` | `5 * 1024 * 1024` | Maximum file size in bytes (default 5MB) |
| `allowedTypes`| `RegExp` | `/jpeg|jpg/` | Allowed file types (e.g., jpeg, jpg) |
