Key differences between require(node.js) and import(javascript)
What is require
Require permits you to load other modules or files into your application.
Syntax
let example = require('./example.js')
What is import
Import is used to import modules where you can selectively load them when you need. They are permitted only in ES modules.
Syntax
import Example from './example.js';
Differences between Require and Import
| Require | Import |
|---|---|
| Loading is Synchronous | Import is Asynchronous |
| Throws error at runtime | Throws error while parsing |
| Nonlexical | Lexical |
| Can be called conditionally | Always declared at the beginning of the program |