A
A
Alexander Ivanov2019-08-03 20:24:42
Node.js
Alexander Ivanov, 2019-08-03 20:24:42

Is it possible to load new data from the database to node.js without restarting the server?

let messages; // получаю список из базы
knex.select().from('messages').timeout(1000).then(res => {
    messages = JSON.stringify(res);
});

router.get('/api', async (ctx, next) => {
    ctx.body = messages; // вывожу
});

If I add new entries to the database, then they are not loaded by refreshing the page, and the server must be restarted.
In php, c#, none of this is needed, all the unloading comes from the current database and I'm confused. Those. Do I need to close the connection every time?
And to make everything on one port loaded is not an option at all ??
or how do they work with this on node? Someone chooses chooses this as the main tool ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2019-08-03
@cimonlebedev

There's nothing to just write code through the ass. Your data is received once, but you need to do the receiving inside the corresponding method, at least (I’ll omit about SOLID, etc. for now)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question