hapi-s3 v2.0.0
hapi-s3 
Provides an instance of Scube, a thin wrapper around the S3 client from the AWS SDK, so you can interact with S3 programmatically. It is available at request.server.s3 in route handlers.
Why?
- Easily implement streaming uploads / downloads.
- Memory efficient, with one instance of the AWS SDK per server.
- Loads credentials explicitly.
Install
npm install hapi-s3Usage
Register the plugin on your server to make request.server.s3 available in route handlers.
const hapi = require('@hapi/hapi');
const s3 = require('hapi-s3');
const server = hapi.server();
const init = async () => {
await server.register({
plugin : s3,
options : {
bucket : 'my-bucket',
publicKey : process.env.AWS_ACCESS_KEY_ID,
secretKey : process.env.AWS_SECRET_ACCESS_KEY
}
});
server.route({
method : 'GET',
path : '/',
async handler(request) {
const { s3 } = request.server;
const buckets = await s3.listBuckets();
return buckets;
}
});
await server.start();
console.log('Server ready:', server.info.uri);
};
init();API
Please see Scube for details on the s3 object.
Plugin options
Type: object
The options are passed to new Scube() to configure the S3 client. See Scube for details on the available options, such as bucket, region, and others.
Decorations
For convenience, this plugin adds the following API to the hapi server instance.
server.s3
An instance of Scube, a thin wrapper around the S3 client from the AWS SDK. This is available as request.server.s3 inside of route handlers.
Related
Contributing
See our contributing guidelines for more details.
- Fork it.
- Make a feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request.
License
Go make something, dang it.