Answer the question
In order to leave comments, you need to log in
What to use module.exports or export default?
When I import or export any object, vs automatically offers to fix this construct. I don’t seem to be studying at the old rate, and it wasn’t mentioned there. Is this the correct design? Or how to make vs ignore it?
Answer the question
In order to leave comments, you need to log in
Both designs are correct. Just a different format of modules.
In a nutshell, requre()/module.exports is a good old CommonJS Module that is supported in any version of Node.js. Node.js 13.2.0 brought support for ES Modules (which are import-export) in experimental mode, you can read an article about this on the medium and, of course, of. doc.
Thus, with ES Modules, you need to take care of compatibility with previous versions of Node.js, with new ones, use Babel, for example, for transpiling in CommonJS. If just for learning on Node.js 13.2.0 and above, you can change the file extension from .js to .mjs and it will work. If you are not ready to deal with this now, it's okay, you can use CommonJS and not worry. As for setting up VSCode, I won’t say, I don’t use it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question