0
0
Node.jsframework~10 mins

CommonJS vs ESM differences in Node.js - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the 'fs' module using CommonJS syntax.

Node.js
const fs = require([1]);
Drag options to blanks, or click blank then click option'
A'filesystem'
B'file-system'
C'fs'
D'Fs'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names like 'file-system' or 'filesystem'.
Capitalizing the module name incorrectly.
2fill in blank
medium

Complete the code to import the 'fs' module using ESM syntax.

Node.js
import fs from [1];
Drag options to blanks, or click blank then click option'
A'fs'
B'Fs'
C'filesystem'
D'file-system'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect module names.
Forgetting to use quotes around the module name.
3fill in blank
hard

Fix the error in exporting a function named 'greet' using CommonJS syntax.

Node.js
module.exports = [1];
Drag options to blanks, or click blank then click option'
A{ greet }
Bfunction greet()
Cgreet()
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function while exporting (e.g., greet()).
Exporting an object instead of the function directly.
4fill in blank
hard

Fill both blanks to export a named function 'greet' using ESM syntax.

Node.js
[1] function greet() { console.log('Hello'); } [2]
Drag options to blanks, or click blank then click option'
Aexport
Bexport default
Cimport
Dmodule.exports
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'export default' for named exports.
Using CommonJS syntax like 'module.exports'.
5fill in blank
hard

Fill all three blanks to import a named export 'greet' from 'greetings.js' using ESM syntax.

Node.js
import [1] from [2];

[3]();
Drag options to blanks, or click blank then click option'
A{ greet }
B'./greetings.js'
Cgreet
Dgreetings
Attempts:
3 left
💡 Hint
Common Mistakes
Importing without curly braces for named exports.
Forgetting quotes around the module path.
Calling the function with wrong name.