{"library":"s3rver","title":"S3rver: Local S3 Mock Server","description":"S3rver is a lightweight, in-memory or file-system-backed server that emulates a significant subset of the Amazon S3 API, designed primarily for local development and testing environments. It allows developers to test S3 interactions without incurring costs or relying on external network requests. The current stable version is `3.7.1`, with development being active and releases addressing bug fixes, performance improvements, and expanding S3 API compatibility. Key differentiators include its focus on being a development-only tool, minimal runtime dependencies, support for programmatic integration into test suites, and simulation of S3's static website hosting capabilities, including website routing rules. It supports common S3 operations like bucket creation/deletion, object CRUD, object tagging, and basic object lifecycle features.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install s3rver"],"cli":{"name":"s3rver","version":null}},"imports":["import S3rver from 's3rver';","const S3rver = require('s3rver');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import S3rver from 's3rver';\nimport { S3Client, CreateBucketCommand, PutObjectCommand, GetObjectCommand, DeleteObjectCommand, DeleteBucketCommand } from '@aws-sdk/client-s3';\nimport { mkdtemp, rm } from 'node:fs/promises';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\n\nasync function runS3rverExample() {\n  const port = 4569;\n  const tempDir = await mkdtemp(join(tmpdir(), 's3rver-example-'));\n  const bucketName = 'my-test-bucket';\n  const objectKey = 'hello.txt';\n  const content = 'Hello from S3rver!';\n\n  console.log(`Using temporary directory: ${tempDir}`);\n\n  // Initialize S3rver instance\n  const s3rver = new S3rver({\n    port: port,\n    directory: tempDir,\n    silent: true, // Suppress S3rver logs for cleaner output\n  });\n\n  // Start the S3rver\n  await s3rver.run();\n  console.log(`S3rver running on http://localhost:${port}`);\n\n  // Configure AWS SDK client to connect to S3rver\n  const client = new S3Client({\n    region: 'us-east-1', // S3rver does not enforce specific regions\n    endpoint: `http://localhost:${port}`,\n    credentials: {\n      accessKeyId: 'S3RVER', // S3rver's default credentials\n      secretAccessKey: 'S3RVER' // S3rver's default credentials\n    },\n    forcePathStyle: true // Required for S3rver\n  });\n\n  try {\n    // 1. Create a bucket\n    await client.send(new CreateBucketCommand({ Bucket: bucketName }));\n    console.log(`Bucket \"${bucketName}\" created.`);\n\n    // 2. Upload an object\n    await client.send(new PutObjectCommand({\n      Bucket: bucketName,\n      Key: objectKey,\n      Body: content,\n      ContentType: 'text/plain'\n    }));\n    console.log(`Object \"${objectKey}\" uploaded.`);\n\n    // 3. Download the object\n    const { Body } = await client.send(new GetObjectCommand({\n      Bucket: bucketName,\n      Key: objectKey\n    }));\n    const downloadedContent = await Body?.transformToString();\n    console.log(`Downloaded object content: \"${downloadedContent}\"`);\n\n    // Verify content\n    if (downloadedContent === content) {\n      console.log('Content verification successful.');\n    } else {\n      console.warn('Downloaded content mismatch!');\n    }\n\n  } catch (error) {\n    console.error('S3 operation failed:', error);\n  } finally {\n    // Clean up: Delete object and bucket\n    try {\n        await client.send(new DeleteObjectCommand({ Bucket: bucketName, Key: objectKey }));\n        await client.send(new DeleteBucketCommand({ Bucket: bucketName }));\n        console.log('Cleaned up bucket and object.');\n    } catch (cleanupError) {\n        console.warn('Error during cleanup:', cleanupError);\n    }\n\n    // Stop the server\n    await s3rver.close();\n    console.log('S3rver stopped.');\n\n    // Remove temporary directory\n    await rm(tempDir, { recursive: true, force: true });\n    console.log(`Removed temporary directory: ${tempDir}`);\n  }\n}\n\nrunS3rverExample().catch(console.error);\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically start and stop an S3rver instance, create a temporary directory for storage, and interact with it using the AWS SDK for JavaScript v3 to create a bucket, upload an object, and retrieve it.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}