DEV Community

Discussion on: Where to put business logic

Collapse
 
davidmaceachern profile image
David MacEachern • Edited

Hi Menning,

If i hence was going to do my calculation in the backend, where would I do them? a function in Express?

It sounds like you might be looking for vercel.com/docs/serverless-functio....

You can work on your React App and have it make API calls this way, you can even deploy the app continuously as you push it to your remote Git repository.

Am I wrong that it is not safe to keep all business logic in the frontend (such as some proritetary calculation)?

It depends, you might want to abstract sensitive operations to a server and consider how the network calls can be secured. If it's an exercise to learn more about React then maybe you don't want to consider those details just now.

Another reason might be if you want to make the application usable by a wide variety of users with varying degrees of connectivity then compute-heavy operations can be offloaded to the server or database. This might change in the future though once Webassembly becomes more widely adopted.

For example, uploading a CSV of transactions for 10 years and then attempting to perform many operations on them might not make sense in the browser storage.

Collapse
 
menning profile image
menning

Brilliant thanks! and you would suggest using serverless functions or would you rather suggest that I use CRA instead of NextJS, i.e. is NextJS not really suited for the type of application I am thinking?

Collapse
 
davidmaceachern profile image
David MacEachern

It depends on what your goal is, how long you want to spend working on this project, if it's a quick exercise then I would just use React.

Thread Thread
 
menning profile image
menning

Great thanks!

Thread Thread
 
davidmaceachern profile image
David MacEachern • Edited

Good luck! You can show us how you get on at showdev