F
F
Fengol2018-04-12 09:38:53
Node.js
Fengol, 2018-04-12 09:38:53

Why doesn't dynamic require work in a route?

There is a module that is compiled on change and there is a route that dynamically loads this module.

router.get( '/info', ( request, response ) => {
    const { Info } = require( 'Info' );

    console.log( Info.getInfo() ); // данные не меняются. Почему?
} )
;
After compiling the Info module, I see the changes in the file, but in the route it shows the old values.
Why and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Coder321, 2018-04-12
@Fengol

Because require caches the first value and changes to the file will not give you anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question