Node.js · Junior · Question 14 of 75

How does Node.js decide that a .js file is an ES module?

Explanation

Without "type": "module", .js files are CommonJS. .mjs is always ESM and .cjs is always CommonJS. Recent versions can also detect ESM syntax in ambiguous files.

Further reading

Problem with a question

Node.js · Junior · question 14

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz