upload-express-middleware
v1.0.2
Published
Express middleware for file uploads using multer
Maintainers
Readme
Express Upload Middleware
A simple and flexible Express middleware for handling file uploads using Multer.
Installation
npm install upload-express-middleware
# or
pnpm add upload-express-middleware
# or
yarn add upload-express-middlewareUsage
import express from 'express';
import { uploadMiddleware } from 'upload-express-middleware';
const app = express();
// Use the upload middleware with a specific folder
app.post('/upload', uploadMiddleware('uploads'), (req, res) => {
if (!req.file) {
return res.status(400).json({ error: 'No file uploaded' });
}
res.json({
message: 'File uploaded successfully',
filename: req.file.filename,
path: req.file.path
});
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});Features
- Dynamic folder creation
- Unique filename generation
- File size limit (5MB by default)
- TypeScript support
- Configurable upload destinations
API
uploadMiddleware(folderName: string)
Creates a multer middleware for handling single file uploads.
Parameters:
folderName(string): The name of the folder where files will be stored
Returns:
- Express middleware function
License
ISC
