CommonJS vs ESM Hint
NodeJS
Medium
3 views
Problem Description
Detect if running in CommonJS and print a friendly note.
Output Format
Print one line.
Constraints
No need to actually switch module types.
Official Solution
const isCommonJS = typeof require === 'function' && typeof module !== 'undefined';
console.log(isCommonJS ? 'CommonJS mode' : 'ESM mode');
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!