Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to correctly return data in nested function in express js function

I am new to learning javascript and Express.js and I can't figure out how to correctly return the value I want. Console.log(data) works, but returning the data shows undefined.

Basically, I want to send the parameters when calling the function and have it return a list of objects in an S3 folder.

Calling the function (S3)

//attach s3

  const image_ref = await db.query("SELECT image_ref FROM projects WHERE created_by = $1 AND name = $2",[user_id,project_name])
  const parameters = image_ref.rows[0].image_ref;
  console.log(S3(parameters));

S3 Function

function S3(parameters) {

let bucket_parameters = JSON.parse(parameters);
const myBucket = bucket_parameters.bucket_name; 
const prefix = bucket_parameters.folder; 
const access_key = bucket_parameters.access_key 
const secret_access_key = bucket_parameters.secret_access_key
const region = bucket_parameters.region


const s3 = new AWS.S3 ({
    accessKeyId: access_key,
    signatureVersion: 'v4',
    region: region,
    secretAccessKey: secret_access_key
});

var bucketParams = {
    Bucket : myBucket,
    Prefix: prefix
};
  
s3.listObjects(bucketParams, function (err, data) {
    if(err)throw err;
    //console.log(data);
    return data;
    });
} 

module.exports = S3;
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!