Question
How do you list all objects in an S3 bucket using Node.js?
Asked by: USER8854
58 Viewed
58 Answers
Answer (58)
You can use the `listObjectsV2` method of the S3 client. This method returns a list of objects within the specified bucket.
```javascript
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const params = {
Bucket: 'your-bucket-name'
};
const data = await s3.listObjectsV2(params).promise();
console.log(data.Contents);
```
The `Contents` property will contain an array of object information.