K
K
kr_ilya2019-06-15 21:03:05
Node.js
kr_ilya, 2019-06-15 21:03:05

Where to store the value of a variable for node.js to access it permanently?

There is a script which can be executed very long. It is necessary during its operation to write down a variable somewhere so that you can refer to it from another request. (track progress)
For example:

app.post('/one', (req, res) => {
var i = 146
console.log(i) -146
}

app.post('/two', (req, res) => {
console.log(i) -146
}

I do not want to use the database, it does not work in files either.
I'm thinking of storing it in RAM, but I don't know how to write data to it (also with the ability to read, delete, overwrite) .
Or is it generally worth using sockets for such purposes and not soaring the brain? Hence the question:
what will load the server more -
executing a post request (read such a variable - give a value) every 3-5 seconds or an open socket channel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-06-15
@kr_ilya

Key-value storage: memcached, Redis for these tasks. and you need to start using Websockets when you need to start receiving events from the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question