Tus Resumable Upload Middleware for Node.js
raw JSON →This package, `tus` (version 0.1.7), provides a Node.js middleware for Express and Connect applications, implementing the tus resumable upload protocol. Originally designed for older versions of Express and Connect, it allows clients to pause and resume file uploads, making it suitable for large files or unreliable network conditions. The package's last update was nine years ago, making it effectively abandoned and incompatible with modern Node.js ecosystems, recent Express/Connect versions, and current JavaScript module standards (ESM). It lacks active maintenance, security patches, and contemporary features found in actively developed alternatives like `tus-node-server`. Its release cadence was sporadic, reflecting a period of early development for the tus protocol itself.
Common errors
error TypeError: app.use() requires middleware functions but got a undefined ↓
const tus = require('tus'); is correct and tus.createServer is being invoked with valid options, returning a middleware function. error Error: Cannot find module 'tus' ↓
npm install tus in your project directory to install the package. error DeprecationWarning: res.send(status) is deprecated ↓
complete callback to res.status(200).send('OK') or res.sendStatus(200) for simple status codes. error Error: EACCES: permission denied, open '/path/to/uploads/temp_file' ↓
directory. Warnings
breaking This package is heavily outdated (last updated 9 years ago) and is incompatible with modern Node.js versions (e.g., Node.js 14+), Express.js (v4+), and Connect.js. It relies on deprecated APIs and patterns, leading to runtime errors or unexpected behavior. ↓
breaking The package is CommonJS-only and does not provide ES Module support. Attempting to `import` it will result in an `ERR_REQUIRE_ESM` or similar error in ES Module contexts. ↓
gotcha The `complete` callback function in the middleware requires manual handling of the HTTP response (`res`). If you implement `complete`, you must explicitly send a response (e.g., `res.send()`, `res.end()`, `res.status().send()`); otherwise, the client connection may hang. ↓
breaking Security vulnerabilities are highly probable due to the lack of maintenance. The package has not received updates for almost a decade, making it vulnerable to known and unknown exploits related to file uploads, path traversal, or denial of service. ↓
Install
npm install tus yarn add tus pnpm add tus Imports
- createServer wrong
import { createServer } from 'tus';correctconst tus = require('tus'); const uploadMiddleware = tus.createServer({ ... }); - * as tus wrong
import * as tus from 'tus';correctconst tus = require('tus');
Quickstart
const express = require('express');
const tus = require('tus');
const path = require('path');
const fs = require('fs');
const app = express();
const port = 3000;
// Ensure the upload directory exists
const uploadDir = path.join(__dirname, 'uploads');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir);
}
app.use('/files', tus.createServer({
directory: uploadDir,
maxFileSize: 1024 * 1024 * 5, // 5 MB limit
complete: function(req, res, next) {
console.log('File upload complete with metadata:', req.upload);
// In modern Express, use res.status().send() or res.sendStatus()
// For older Connect/Express, res.end() was common for simple responses.
res.status(200).send('Upload successful');
// If not calling next(), ensure the response is manually handled.
}
}));
app.listen(port, () => {
console.log(`Tus server listening on port ${port}`);
console.log(`Upload directory: ${uploadDir}`);
});
// Example: Basic route to serve the client-side uploader (not included in this snippet)
app.get('/', (req, res) => {
res.send('Tus upload server running. Use a tus client to upload to /files.');
});