Next.js Discord

Discord Forum

Where to put server side helper functions

Answered
Japanese jack mackerel posted this in #help-forum
Open in Discord
Avatar
Japanese jack mackerelOP
Where do i put a file thats intended solely to be called on the backend side for helper functions?
Answered by gin
every file is serversided default
View full answer

6 Replies

Avatar
Japanese jack mackerelOP
as in i have a areaOfSquare function that id like to call. its not a component and should never be called directly by the front end
Avatar
every file is serversided default
Answer
Avatar
"use client" at the top transforms it into clientside
so if u create a file named -> helper.ts this will be available securely on the server
If u want to go a extra step more secure, i would suggest importing server-only at the top to make sure not to accidentally expose something on the client