Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Examples

This directory contains working examples demonstrating various use cases of `node-uploadx`.

## Running Examples

From the repository root, install dependencies and build `node-uploadx` packages first:

```bash
npm install
npm run build
```

Then navigate to the examples directory and run the desired script:

```bash
# Basic Express example
npm run basic

# Express with default storage (local filesystem)
npm run express

# Express with S3 storage
npm run s3

# Express with GCS storage
npm run gcs

# Plain Node.js server combining Uploadx, TUS and Multipart protocols
npm run server

# Plain Node.js HTTP server example
npm run plain-nodejs

# Other examples...
npm run tus
npm run validation
npm run redis
npm run logtape
npm run custom-error-responses
npm run express-polling
```

## Example Descriptions

| File | Description |
| -------------------------------------------------------- | ------------------------------------------------------------------- |
| [`express.ts`](express.ts) | Express example with authentication and logging |
| [`express-basic.ts`](express-basic.ts) | Minimal Express setup with local file storage |
| [`express-s3.ts`](express-s3.ts) | Upload to AWS S3 |
| [`express-gcs.ts`](express-gcs.ts) | Upload to Google Cloud Storage |
| [`express-tus.ts`](express-tus.ts) | Using the tus resumable upload protocol |
| [`express-polling.ts`](express-polling.ts) | Polling-based upload implementation |
| [`express-redis.ts`](express-redis.ts) | Using Redis for metadata storage |
| [`express-logtape.ts`](express-logtape.ts) | Logging with LogTape |
| [`custom-error-responses.ts`](custom-error-responses.ts) | Custom error handling and responses |
| [`validation.ts`](validation.ts) | File validation (type, size, custom rules) |
| [`s3-direct.ts`](s3-direct.ts) | Direct S3 upload |
| [`gcs-direct.ts`](gcs-direct.ts) | Direct GCS upload |
| [`node-http-server.js`](node-http-server.js) | Plain Node.js HTTP server example |
| [`server.js`](server.js) | Plain Node.js server combining Uploadx, TUS and Multipart protocols |

## Prerequisites

Most examples require environment variables. Copy `.env.example` to `.env` and fill in the values:

```env
# Required for all examples
UPLOAD_DIR=./files

# For S3 examples (aws s3, minio, etc.)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret
AWS_REGION=us-east-1
S3_BUCKET=your-bucket

# For GCS examples
GCS_BUCKET=your-bucket
GCS_KEY_FILE=/path/to/key.json

# Optional
UPLOADX_SECRET=your-secret-key
```

See `.env.example` for full environment variable reference.
2 changes: 1 addition & 1 deletion examples/custom-error-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const storage = new DiskStorage({
logLevel: 'debug',
onError(response) {
const { code, message } = response;
const page = (code || 'unknownerror').toLowerCase();
const page = (code || 'UnknownError').toLowerCase();
const documentation_url = `http://example.com/api/v1/docs/upload/error/${page}`;
const body = { message, documentation_url };
return { ...response, body };
Expand Down
2 changes: 1 addition & 1 deletion examples/express-polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ app.use('/files', upload, async (req, res) => {
: res.json({ ...file, taskStatus: 'done' });
});

app.listen(PORT, () => console.log(`Listing on port ${PORT}`));
app.listen(PORT, () => console.log('listening on port:', PORT));