Recall & Review
beginner
What is CommonJS in Node.js?
CommonJS is a module system used in Node.js that uses require() to load modules and module.exports to export them. It loads modules synchronously.
Click to reveal answer
beginner
What does ESM stand for and what is its main feature?
ESM stands for ECMAScript Modules. It is the official JavaScript module system that uses import and export syntax and supports asynchronous loading.Click to reveal answer
intermediate
How do you export a function in CommonJS vs ESM?
In CommonJS: module.exports = functionName;
In ESM: export function functionName() {} or export default functionName;Click to reveal answer
intermediate
Can CommonJS and ESM modules be mixed in the same Node.js project?
Yes, but with some restrictions. ESM can import CommonJS modules, but CommonJS cannot directly import ESM without dynamic import or special handling.Click to reveal answer
beginner
What file extensions and package settings indicate ESM usage in Node.js?
Files with .mjs extension or .js files with "type": "module" in package.json are treated as ESM modules.
Click to reveal answer
Which syntax is used to import modules in ESM?
✗ Incorrect
ESM uses the import statement like 'import moduleName from "module";' to load modules.
Which module system loads modules synchronously in Node.js?
✗ Incorrect
CommonJS loads modules synchronously using require(), while ESM supports asynchronous loading.
How do you mark a Node.js project to use ESM for .js files?
✗ Incorrect
Setting "type": "module" in package.json tells Node.js to treat .js files as ESM modules.
Which of these is NOT true about CommonJS and ESM?
✗ Incorrect
CommonJS does NOT support top-level await; this is a feature of ESM.
Can CommonJS modules import ESM modules directly using require()?
✗ Incorrect
CommonJS cannot directly import ESM modules with require(); dynamic import() or other methods are needed.
Explain the main differences between CommonJS and ESM module systems in Node.js.
Think about how modules are loaded and how you write import/export code.
You got /5 concepts.
Describe how you can use both CommonJS and ESM modules together in a Node.js project.
Consider interoperability and loading methods.
You got /4 concepts.