node learning

Posted May 26, 20201 min read

1.exports, module.exports, require

1) exports and module.exports

require:introduction of node support

export/import:only es6 supports export import

module.exports/exports:only exports supported by node


let a = 1;
let b = 2;


console.log(module.exports); //print {}
console.log(exports); //print {}
//Two are equivalent to exporting empty objects

2) require

//export file
let a = 1;
let b = 2;


module.exports = {
    a:a,
    b:b
}

//Importing files
const num = require('./index1')
console.log(num); //print {a:1, b:2}

2. Import module
let $= require('jquery')

  1. This code will find node \ _modules in the same directory of the current file, and find the package.json file under node \ _modules, and then find the main attribute


2.dist/jquery.js file is the current entry file of the imported module