npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-easy-fileuploader

v1.0.2

Published

easy express file uploader (laravel like)

Downloads

11

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 uses the old package 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)

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'>