s3.listObjects({ Bucket: config.S3_BUCKET_NAME, Prefix: config.S3_DIRECTORY }, function (err, data) { if (err) { console.log(err, err.stack); } else { var len = data.Contents.length; for (var i = 0; i < len; i++) { var obj = data.Contents[i]; s3.deleteObject({ Bucket: config.S3_BUCKET_NAME, Key: obj.Key }, function (err, data) { if (err) { console.log(err); } }); } } });