How to create utility functions

I am trying to create utility functions under a file that I created in a Serverless function directory.

How am I able to use that function on the endpoint file? Because I keep getting the error below

I exported the function on that seperate file as

exports.getProperties = getProperties;

And then called that function on the endpoint file as

const { getProperties } = require("./utils.js");

Hi, @SaltyKaren :waving_hand: Thanks for reaching out! One troubleshooting step to get the community more information — have you tried logging your __dirname in the lambda function to see what the actual path is where your code is running? This could help debug path issues.

Best,

Jaycee

Hey SaltyKaren! I feel your pain with those function struggles. So, when you’re trying to use your utility function on the endpoint file, the error might be a path issue. Double-check if your utils.js file is in the right place or if you need to tweak that “./utils.js” import.

Also, make sure your exports are on point. Your “exports.getProperties = getProperties;” looks good, but ensure there’s no funky business going on in the function itself. Maybe throw in a console.login the utility function to see if it’s even getting called.

Been there, done that. For me, clarity comes first. I’d organize my folders like my life depends on it. Try restructuring if needed. And hey, console.log is your debugging buddy. Slap some of those around to trace the issue. I had an experience with a similar project and this saved me: Energy Software Development Company – Andersen

Hope this helps! Don’t hesitate to toss more details my way if you need more brainstorming.