# How to create utility functions

**URL:** <https://community.hubspot.com/t/how-to-create-utility-functions/86528>\
**Category:** CMS Development\
**Tags:** local-development, javascript\
**Created:** [August 1, 2023, 5:05am UTC](https://community.hubspot.com/t/how-to-create-utility-functions/86528 "2023-08-01T05:05:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaltyKaren](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/saltykaren/32/34870_2.png) [@SaltyKaren](https://community.hubspot.com/u/SaltyKaren)\
**Post date:** [August 1, 2023, 5:05am UTC](https://community.hubspot.com/t/how-to-create-utility-functions/86528/1 "2023-08-01T05:05:57Z")

</div>

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

 ![Screenshot 2023-08-01 at 1.01.53 PM.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/4/e44e15feaa12ce9f0ec4cd91d69347c7473fe4c3.png)

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");`

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [August 1, 2023, 9:34pm UTC](https://community.hubspot.com/t/how-to-create-utility-functions/86528/2 "2023-08-01T21:34:31Z")

</div>

Hi, @SaltyKaren 👋 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

---

<div class="post-metadata">

**Author:** ![AGaz](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@AGaz](https://community.hubspot.com/u/AGaz)\
**Post date:** [December 26, 2023, 9:23am UTC](https://community.hubspot.com/t/how-to-create-utility-functions/86528/3 "2023-12-26T09:23:08Z")

</div>

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](https://andersenlab.com/industries/custom-energy-management-software)

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