Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the 'fs' module using CommonJS require.
Node.js
const fs = [1]('fs');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'import' instead of 'require'
Using 'include' or 'load' which are not valid in CommonJS
✗ Incorrect
In CommonJS, require is used to import modules.
2fill in blank
mediumComplete the code to export a function named 'greet' using module.exports.
Node.js
module.exports = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using greet() which calls the function instead of exporting it
Using braces which exports an object, not the function itself
✗ Incorrect
You assign the function name directly to module.exports to export it.
3fill in blank
hardFix the error in importing the default export from 'math.js' using require.
Node.js
const add = [1]('./math.js');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'import' which is ES Modules syntax
Using 'fetch' or 'include' which are invalid here
✗ Incorrect
Use require to import modules in CommonJS, not import.
4fill in blank
hardFill both blanks to export an object with two functions, 'start' and 'stop'.
Node.js
module.exports = { [1], [2] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function names that do not exist
Forgetting to export both functions
✗ Incorrect
Export an object with keys matching the function names you want to export.
5fill in blank
hardFill all three blanks to import 'readFile', export a function 'writeFile', and assign it to module.exports.
Node.js
const { [1] } = require('fs');
function [2](path, data) {
// write data to file
}
module.exports = [3]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up imported and exported function names
Not exporting the function correctly
✗ Incorrect
You import readFile from 'fs', define writeFile function, and export it.