0
0
Node.jsframework~5 mins

ES Modules import and export in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main purpose of ES Modules in Node.js?
ES Modules allow you to organize and reuse code by importing and exporting functions, objects, or values between files in a clear and standardized way.
Click to reveal answer
beginner
How do you export a single function as the default export in an ES Module?
Use export default functionName; to export a single function as the default export from a module.
Click to reveal answer
beginner
What is the syntax to import a default export from another module?
Use <code>import anyName from './module.js';</code> where <code>anyName</code> is your chosen name for the default export.
Click to reveal answer
intermediate
How do you export multiple named values from a module?
Use <code>export const name1 = value1;</code> or <code>export { name1, name2 };</code> to export multiple named values.
Click to reveal answer
intermediate
How can you import multiple named exports from a module?
Use <code>import { name1, name2 } from './module.js';</code> to import specific named exports.
Click to reveal answer
Which keyword is used to export a default value in ES Modules?
Arequire
Bexport const
Cmodule.exports
Dexport default
How do you import a named export called calculate from a module?
Aimport { calculate } from './module.js';
Bimport calculate from './module.js';
Cconst calculate = require('./module.js');
Dexport { calculate } from './module.js';
What file extension should you use for ES Modules in Node.js by default?
A.mjs
B.cjs
C.js
D.json
Which statement is true about mixing CommonJS and ES Modules in Node.js?
AYou can freely mix <code>require</code> and <code>import</code> in the same file.
BES Modules can import CommonJS modules, but CommonJS cannot import ES Modules directly.
CCommonJS modules are the same as ES Modules.
DYou must rename all files to .cjs to use ES Modules.
How do you export a variable named count as a named export?
Aexport default count;
Bimport count from './module.js';
Cexport { count };
Dmodule.exports = count;
Explain how to export and import both default and named values using ES Modules in Node.js.
Think about how you share one main thing versus multiple things from a file.
You got /4 concepts.
    Describe the difference between ES Modules and CommonJS modules in Node.js and how they interact.
    Consider the keywords and compatibility between the two module systems.
    You got /4 concepts.