#Server memory ?

4 messages · Page 1 of 1 (latest)

junior seal
#

Hi. I'm new to server-side rendering, so I was wondering, how can my server retain in memory a save state ? For example, how would I keep count of the total amount of pages that have been accessed or requested so far ?

junior seal
#

I'd like to replicate the behaviour of this nodejs script, but inside Astro:

const http = require('http');
let count = 0;

setInterval(() => {
  count++;
}, 1000);

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/html' });
  res.write(`<h1>Count: ${count}</h1>`);
  res.end();
});

server.listen(4321, () => {
  console.log('Server running at http://localhost:4321/');
});

This increments a variable, every second, and I can see this variable update if I refresh my page

junior seal
#

I should specify that I am currently configured with NodeJS server rendering using the Standalone mode. Is it possible or would I be required to use the middleware mode ?

junior seal
#

I was able to get a working solution by installing and using ExpressJs. Can I do without ?