npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

s3-nodejs-sample

v1.0.9

Published

--- ###### This is a node module illustrating usage of the AWS SDK for Node.js.To use this just dowload this module,set credentials in node_modules/s3-nodejs-sample/config.js file and use below functions. ---

Downloads

7

Readme

s3-nodejs-sample

Author: Chandrakant Thakkar

Created on: 13th January,2017

This is a node module illustrating usage of the AWS SDK for Node.js.To use this just dowload this module,create config.js file to set credentials and use below functions.

Requirements

The only requirement of this application is the Node Package Manager. All other dependencies (including the AWS SDK for Node.js) can be installed with:

 npm install

Basic Configuration

You need to set up your AWS security credentials before the sample code is able to connect to AWS. You can do this by creating setting accessKeyId,secretAccessKey,proxy parameters in config.js file. Open config.js file and set the parameters:

credentials={
 "accessKeyId" : "****",
 "secretAccessKey" :"****",
 "proxy":"****"
}
module.exports={
 credentials:credentials
}

See the Security Credentials page. It's also possible to configure your credentials via a configuration file or directly in source. See the AWS SDK for Node.js Developer Guide for more information.

"accessKeyId" and "secretAccessKey" are provided when you create an aws account.

Proxy is required if you are using your company's internet else set "localhost" in proxy.

Running the S3 sample

 node sampleFile.js

List of Functions

  1. createBucket()
  2. createFile()
  3. uploadFile()
  4. getUploadedFile()
  5. getFileData()
  6. listAllBucket()
  7. listAllFiles()
  8. removeFile()
  9. removeBucket()
  10. getBucketPermission()
  11. isBucketExist()
  12. getObject()

1. createBucket()

  • Example
var s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.createBucket(bucketName,config,function(data){
 if(data.status==false){
  console.log("Error in Bucket Creation:"+data.error);
 }else{
  console.log("Bucket Created");
 }
});

2. createFile()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
var fileName="sampleFile.txt";
var fileContents="This is demo created by Chandrakant Thakkar.";
s3BucketMgt.createFile(bucketName,fileName,fileContents,config,function(data){
 if(data.status==false){
  console.log("Error in File Creation:"+data.error);
 }else{
  console.log("File Created in Bucket.");
 }
});

3. uploadFile()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
var fileToUpload = "D:/gitHub/awt-nodejs-sample/s3-nodejs-sample/logo.jpg";
s3BucketMgt.uploadFile(bucketName,fileToUpload,"null",config,function(data){
 if(data.status==false){
  console.log("Error in Upload file:"+data.error);
 }else{
  console.log("File Uploaded in Bucket.");
 }
});

or
//CBT:create file with specific name
var fileToCreate="sample.jpg"
s3BucketMgt.uploadFile(bucketName,fileToUpload,fileToCreate,config,function(data){
 if(data.status==false){
  console.log("Error in Upload file:"+data.error);
 }else{
  console.log("File Uploaded in Bucket.");
 }
});

4. getUploadedFile()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.getUploadedFile(bucketName,"logo.jpg","null",config,function(data){
 if(data.status==false){
  console.log("Error in getting uploaded File:"+data.error);
 }else{
  console.log("File created on Local.");
 }
});

5. getFileData()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
var fileName="sampleFile.txt";
s3BucketMgt.getFileData(bucketName,fileName,"null",config,function(data){
 if(data.status==false){
  console.log("Error in getting File data:"+data.error);
 }else{
  console.log("File created on Local.");
 }
});

6. listAllBucket()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
s3BucketMgt.listAllBucket(config,function(data){
 if(data.status==false){
  console.log("Error in getting list of Buckets:"+data.error);
 }else{
  console.log("Buckets:"+JSON.stringify(data.content));
 }
});

7. listAllFiles()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.listAllFiles(bucketName,config,function(data){
 if(data.status==false){
  console.log("Error in getting list of Files:"+data.error);
 }else{
  console.log("Files In Bucket:"+(data.content));
 }
});

8. removeFile()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
var fileName="sampleFile.txt";
s3BucketMgt.removeFile(bucketName,fileName,config,function(data){
 if(data.status==false){
  console.log("Error in Remove file:"+data.error);
 }else{
  console.log("File removed on from Bucket:"+bucketName);
 }
});

9. removeBucket()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.removeBucket(bucketName,config,function(data){
 if(data.status==false){
  console.log("Error in Remove Bucket:"+data.error);
 }else{
  console.log("Bucket is removed:"+bucketName);
 }
});

10. getBucketPermission()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.getBucketPermission(bucketName,config,function(data){
 if(data.status==false){
  console.log("Error in getting list of Buckets:"+data.error);
 }else{
  console.log("Buckets:"+JSON.stringify(data.content));
 }
});

11. isBucketExist()

  • Example
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
s3BucketMgt.isBucketExist(bucketName,config,function(data){
 if(data.status==false){
  console.log("error in isBucketExist:"+data.error);
 }else{
  console.log("Bucket exist:"+data.isExist);
 }
});

12. getObject()

  • Example
//CBT:It will return binary format of data
s3BucketMgt=require("s3-nodejs-sample");
var config=require("./config.js");
var bucketName="node-sdk-sample-cbt-003";
var fileName="logo.jpg";
s3BucketMgt.getObject(bucketName,fileName,config,function(data){
 if(data.status==false){
  console.log("error in getObject:"+data.error.code);
 }else{
  console.log("Object data in Binary:"+data.content.Body);
 }
});