Require() vs import

To import JavaScript modules the require() is used, however it is a part of old CommonJS that was initially devised for Node.js (server-side JavaScript). After ES6 (ECMAScript 2015) got released the import keyword became the new standard.

var name = require('module');

Equivalent in ES6:

import name from 'module';

The advantage of the import statement is that you can import a part of the module. E.g.

import { part } from 'module';

Another difference is that loading for require is synchronous (sequential) and for import asynchronous (parallel) so it can be faster than require.

Category