How to save server-side data

Hi. This isn’t a site-specific question but to fulfill the question requirements, I might apply this on my site https://allaboutdrums.netlify.app

My question is: Is there a way to save data on the server side (the intent being to store the data in a static, client-independent way) on Netlify? As a very simple example, is there a way to trigger, through JavaScript, storage of a small piece of a data on the server, for instance through a call to a Netlify function?

To give a more specific example, can I save a variable/value containing the number of visitors to my site, and then write some JavaScript code (in client side code and/or in Netlify functions) to increment the stored server-side value by one each time a JavaScript event (e.g. the “home” (index.html) document loading on the client side)? I thought about environment variables but they can only be read from, not written to, correct?

Basically, is there any way to store anything on the server side on Netlify? Thanks.

EDIT: I continued to search topics after posting my question and found this page regarding storing data persistently: Can Netlify Functions share cache/memory? - Support - Netlify Support Forums

However, I could not see any documentation/examples on how to use/access Fauna DB in any of the linked pages over there.

Specifically to Netlify, no, you can’t store data.

You can however use something like FaunaDB, Firebase Real Time Database, etc. to store the data, and update and fetch it using Netlify Functions. Here’s an example to get data from FaunaDB: https://github.com/Hrishikesh-K/OpinionJS/blob/main/src/functions/getComments.js

1 Like

@sirjubjubbird No, it is not possible to save anything server-side on Netlify because Netlify doesn’t send files from a server. All files are served from its CDN.

1 Like

Got it. Appreciate the reply and the example code.

I just looked up Firebase as well, and between it and Fauna DB, it looks like the latter will be simpler for me to implement.

Cheers.

Got it. Your reply prompts me to learn more about how the Netlify CDN actually works, but may be that’s for another day.