Node.js · Junior · Question 17 of 75

What does require() do if the same module is required twice?

Explanation

Modules are cached after the first load (in require.cache). That's why a module can hold shared state, such as a database connection, for the whole app. ES modules are cached too.

Further reading

Problem with a question

Node.js · Junior · question 17

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz