Skip to main content
Node.js Output Prediction Easy +10 XP

require vs import

Which syntax is used in CommonJS modules?

Node.jsRead-only
const fs = require('fs');
// vs
import fs from 'fs';

What is the output?

Show answer and explanation

Answer: require() is CommonJS, import is ESM

Node.js supports both CommonJS (require/module.exports) and ES Modules (import/export). They cannot be mixed in the same file.

Hint: Node has two module systems.

What this challenge tests

Output Prediction in Node.js: modules, commonjs, esm.

Related challenges