Node.js ES Module Syntax with 'type': 'module'

In one of my recent encounter with junior , I was asked: Why do we add type: "module" in package.json? might seem like a simple question but it checks your fundamentals. By default, Node.js uses CommonJS (require statement) but if we want to use modern import and export, we add: "type": "module" This tells Node to treat our project as an ES Module. Without it, it gives a syntax error. #nodeAtDept #question # node #javascript #interview

To view or add a comment, sign in

Explore content categories