About exports; module.exports ; export; export default distinguish

1. About exports and module.exports (node is operational)
  • When a node executes a file, an exports and module object will be generated in the file,
    Module has an exports attribute.
  • exports = module.exports = {};


var frist1 = 1
module.exports = frist1


const frist1 = require('./exports.js');

Run: node importm.js

2. About export and export default
  • Both export and export default can be used to export constants, functions, files, modules, etc
  • In a file or module, there can be multiple export and import, and only one export default
  • To export through export mode, you need to add {} when importing, but do not need to use export default
  • Export can directly export variable expressions, but export default cannot.

reference resources:


Recommended Today

Array of algorithms — sum of three numbers

Sum of three numbers difficultysecondary Here is an array of N integersnums, judgmentnumsAre there three elements a, B, C in a such that a + B + C = 0? Please find all triples that satisfy the condition and do not repeat.be careful:The answer cannot contain duplicate triples. Example:Given array nums = [- 1, 0, […]