#Where to store common types shared between client and server?

9 messages · Page 1 of 1 (latest)

drifting mantle
#

I thought at first to use the utils folder, but then the documentation specifically says:

"These utils are only available within the Vue part of your app.
Only server/utils are auto-imported in the server/ directory."

Where is it recommended to store shared functions and types? ☺️ (besides components and composables, which I understand can be used from anywhere when stored in the folders by the same names)

drifting mantle
#

I ended up creating a folder at the root to store common types './types'

Not sure this is best practice, or if this will even work after build? Not sure how Nuxt works behind the scenes, so maybe this only works in dev

twin flare
#

I also use a types folder or file for that usually

#

for functions, you can use utils for nuxt/client-related utils and "server/utils" for server/api-related utils

#

But I would highly advise to not put composables in there and keep the semantic meaning - https://www.youtube.com/watch?v=N0QrFKBZuqA

💚 Vue's Composition API is amazing and my preferred way to write components nowadays. But often I see that developers don't know when functions are Vue composables, and when they are plain functions. Do you know?

In this video we will cover exactly this:
🧠 Explaining what a Vue composable actually is
✅ Going through a checklist to figure out if...

▶ Play video
drifting mantle
#

Thank you! 😊

#

Is it okay to create any folders in the root i want and use from them? I do have a lot of utils that are useful for both client side and server side, so creating new folders at the root are initially shared unless it's a special folder?

twin flare
#

👐🏻 Utility functions and objects are important when building a Nuxt application. Usually they are separate for the Nitro and Nuxt part, but sometimes you have shared utilities you want to re-use in both... But how? 🌟

In this short Mighty Bite video, we'll have a look into how we deal with these shared utilities best, while still keeping the cap...

▶ Play video