Where should I put generic utility code?

System Information
  • Strapi Version: 3.5.4
  • Operating System: Linux
  • Database: Sqlite3
  • Node Version: 14.16.1
  • NPM Version: 6.14.12
  • Yarn Version: 1.22.10

Hello

I’m developing my custom API by writing code in controllers, graphql schema files, and services, as shown in the documentation. But I’m extracting a lot of utility functions that I’d like to share between different services. What is the best or conventional place to put them? Should I create a top-level src directory and just require('../../../src/someUtility.js')? It doesn’t seem very clean and I’m wondering if it wouldn’t play well with auto-reloading and other Strapi features.

Use functions:

Take a look at the example that I’ve provided in another post:

1 Like

This exactly, there is a folder for functions that you can call from anywhere

How about functions that are generic but only relevant to one api?

Model Services: Backend customization - Strapi Developer Documentation

1 Like

ok! But then how can I access this generic fns?