score:17

Accepted answer

What is the preferred method and what is the difference between using const and import?

In 2016 it makes sense to stick with the import since that's the part of the standard.

There is no technical reason to prefer import over require though: everything that can be done using require can be done with import and vice versa. In some cases one will be more concise, in another - the other.

To summarise: choose the one that fits the project code conventions/consistency.

score:1

Of course the main difference is older require vs newer 'import', (as it can be var instead of 'const', does not matter much).

As both are require and import are both valid and supported, some developers may wonder which to use. And generally it is better agree within team to use newer 'import' with strict mode and and exact other ES feature.

Pro and Cons opinions are in Using Node.js require vs. ES6 import/export


Related Query

More Query from same tag