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

@webgeodatavore/tus-node-server

v0.2.3

Published

Node.js tus server

Downloads

3

Readme

tus-node-server

npm version Build Status Coverage Status Dependency Status

tus is a new open protocol for resumable uploads built on HTTP. This is the tus protocol 1.0.0 node.js server implementation.

Installation

$ npm install tus-node-server

Flexible Data Stores

  • Local File Storage

    server.datastore = new tus.FileStore({
        path: '/files'
    });
  • Google Cloud Storage

    
    server.datastore = new tus.GCSDataStore({
        path: '/files',
        projectId: 'project-id',
        keyFilename: 'path/to/your/keyfile.json',
        bucket: 'bucket-name',
    });
  • Amazon S3 (coming soon)

    
    server.datastore = new tus.S3Store({
        path: '/files',
        bucket: 'bucket-name',
    });

Quick Start

Use the tus-node-deploy Docker image

$ docker run -p 49160:8080 -d bhstahl/tus-node-deploy

Build a standalone server yourself

const tus = require('tus-node-server');

const server = new tus.Server();
server.datastore = new tus.FileStore({
    path: '/files'
});

const host = '127.0.0.1';
const port = 8000;
server.listen({ host, port }, () => {
    console.log(`[${new Date().toLocaleTimeString()}] tus server listening at http://${host}:${port}`);
});

Use tus-node-server as Express Middleware

const tus = require('tus-node-server');
const server = new tus.Server();
server.datastore = new tus.FileStore({
    path: '/files'
});

var app = express();
app.all('/files/*', function(req, res) {
  server.handle(req, res);
});
app.listen(port, host);

Features

Events:

Execute code when lifecycle events happen by adding event handlers to your server.

const Server = require('tus-node-server').Server;
const EVENTS = require('tus-node-server').EVENTS;

const server = new Server();
server.on(EVENTS.EVENT_UPLOAD_COMPLETE, (event) => {
    console.log(`Upload complete for file ${event.file.id}`);
});
  • EVENT_FILE_CREATED: Fired when a POST request successfully creates a new file

    Example payload:

    {
        file: {
            id: '7b26bf4d22cf7198d3b3706bf0379794',
            upload_length: '41767441',
            upload_metadata: 'filename NDFfbWIubXA0'
         }
    }
  • EVENT_ENDPOINT_CREATED: Fired when a POST request successfully creates a new upload endpoint

    Example payload:

    {
        url: 'http://localhost:8000/files/7b26bf4d22cf7198d3b3706bf0379794'
    }
  • EVENT_UPLOAD_COMPLETE: Fired when a PATCH request finishes writing the file

    Example payload:

    {
        file: {
            id: '7b26bf4d22cf7198d3b3706bf0379794',
            upload_length: '41767441',
            upload_metadata: 'filename NDFfbWIubXA0'
        }
    }

Custom GET handlers:

Add custom GET handlers to suit your needs, similar to Express routing.

const server = new Server();
server.get('/uploads', (req, res) => {
    // Read from your DataStore
    fs.readdir(server.datastore.path, (err, files) => {
        // Format the JSON response and send it
    }
});

Custom file names:

const fileNameFromUrl = (req) => {
    return req.url.replace(/\//g, '-');
}

server.datastore = new tus.FileStore({
    path: '/files',
    namingFunction: fileNameFromUrl
});

Development

Start the demo server using Local File Storage

$ npm run demo

Or start up the demo server using Google Cloud Storage

$ npm run gcs_demo

Then navigate to the demo (localhost:8000) which uses tus-js-client