How can I download a file from AWS S3 using Node.js?

Question

Grade: Education Subject: Support
How can I download a file from AWS S3 using Node.js?
Asked by:
52 Viewed 52 Answers

Answer (52)

Best Answer
(510)
You can download a file from AWS S3 using Node.js by using the AWS SDK for JavaScript (aws-sdk). The following code snippet shows a basic example: `const AWS = require('aws-sdk'); const s3 = new AWS.S3(); const params = { bucket: 'your-bucket-name', key: 'your-file-key' }; s3.getObject(params).then(data => { console.log(data.Body.toString('utf-8')); }).catch(err => { console.log(err); }); Remember to configure your AWS credentials (e.g., using environment variables or IAM roles) before running this code.