Node.js Interview Question: Why Add 'module' in package.json?

In one of my recent interviews, 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. #interview #react #node #nodejs #reactjs #job #js #interviewquestion

To view or add a comment, sign in

Explore content categories