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

fileupload

v1.0.0

Published

Route middleware for handling file uploads in Express

Downloads

728

Readme

build status

fileupload

This module's main aim is to make file uploads even easier in Node.JS. In it's simplest form, when instantiated, this module returns 4 functions:

  • middleware - route middleware
  • get - to retrieve uploaded files
  • put - to add files to the upload directory
  • delete - to remove uploaded files

Currently only supporting file based uploads, in the near future will support GridFS (mongo db data store), S3 (amazon simple storage services) and SFTP.

This module removes the uploaded files after successful upload.

Installation

 npm install fileupload

Usage

middleware()

Route middleware for connect to process file uploads.

File uploads have been built in to Connect since 1.8, but they dont come in to the post body (req.body) like other form fields, they get put into req.files.

This piece of route middleware moves the files to the upload directory specified in the constructor and adds the files to req.body as if they were normal form fields.

 var fileupload = require('fileupload').createFileUpload('/uploadDir').middleware

 app.post('/upload', fileupload, function(req, res) {
   // files are now in the req.body object along with other form fields
   // files also get moved to the uploadDir specified
 })

###get()

Retrieves a file from the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir')

 fileupload.get('path-to-uploaded-file.gif', function(error, data) {
   // data is the contents of the file
 })

###put()

Puts a file to the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir')

 fileupload.put('path-to-file.gif', function(error, file) {
   // file is an object with information about the uploaded file
   // See below for the contents of this object
 })

###delete()

Deletes a file from the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir')

 fileupload.delete('path-to-file.gif', function(error) {

 })

###File object The file objects that are returned from the middleware and put actions contain the following fields:

  • size - size of the file

  • type - mime type of the file

  • path - the folder name that the file has been stored in

  • basename - the name of the file

Here is an example file object:

 {
   size: 3909,
   type: 'image/gif',
   path: 'b36e7d8a26e5dac9be9d9a5ad76cedb5/',
   basename: 'test1.gif'
 }

Todo

  • GridFS
  • S3
  • SFTP
  • Better code documentation

Credits

Dom Harrington

License

Licensed under the New BSD License