Why use import instead of require()?


#1

Question

Why use import instead of require() ?

Answer

We can use import to import pieces of our a module or an entire module. With require() we will be importing an entire module. So say we have a module with 15 methods, but we only need one of those methods - using import with named exports allows us to import the single method we need from the module, saving both time and memory, whereas require() will import all 15 methods (the entire module assigned to module.exports ).