Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

Which statement about ES modules in Node.js is correct?

  1. A require() can load an ES module synchronously
  2. B An ES module can import a CommonJS module, but CommonJS cannot require an ES module
  3. C ES modules are enabled by default in every Node version
  4. D ES modules provide __dirname automatically
Answer

An ES module can import a CommonJS module, but CommonJS cannot require an ES module

require is synchronous while ESM resolution is asynchronous, which creates the asymmetry. Under ESM, use import.meta.url instead of __dirname.

All NodeJS MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as