Here is the code.
// Require AWS SDK for Node.js
const AWS = require('aws-sdk');
// Set S3 as the service
const s3 = new AWS.S3();
// Configure parameters for file upload
const params = {
Bucket: 'your-bucket-name',
Key: 'example-file.txt',
Body: 'Hello, world!' // File content
};
// Upload file to S3
s3.upload(params, (err, data) => {
if (err) {
console.error('Error uploading file:', err);
} else {
console.log('File uploaded successfully:', data.Location);
}
});