W
W
WebDev2019-07-29 15:26:46
Node.js
WebDev, 2019-07-29 15:26:46

How to update nodejs application so as not to lose data?

On my site, people open different pages, view and edit them.
Each action is tracked on the server via websockets.
I wrote a small nodejs application for this, something like this:

let modifyingPages = 0;
let browsingPages = 0;
let creatingPages = 0;

ws.on('message', json => {
    const msg = JSON.parse(json);

    if (msg.type === 'startModifyPage') {
        this.modifyingPages++;
    } else if (msg.type === 'finishModifyPage') {
        this.modifyingPages--;
    } else if (msg.type === 'startBrowsePage') {
        this.browsingPages ++-;
    } else if (msg.type === 'finishBrowsePage') {
        this.browsingPages --;
    } else if (msg.type === 'startCreatePage') {
        this.creatingPages ++;
    } else if (msg.type === 'finishCreatePage') {
        this.creatingPages --;
    }
});

In general, when a user performs some action, it is recorded in a counter, and this counter is displayed for everyone to see. Some statistics in real time.
The problem is that when I modify this file, I need to restart it, and restarting it resets the counter.
How do they act in such cases?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2019-07-29
@kirill-93

Save in a separate place.
For example, if you do not want to raise a separate database, then you can locally mark data that did not go to your database.
If the local data is equal to the data in the database, then clean the local data, and if not, then upload it to yourself, and then clean it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question