Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Methods of Module Export and Import in node and ES6

Shulou Source: shulou.com Published: 2022-05-31 13:31:54 09月26日 Update

In this article Xiaobian for you to introduce in detail "node and ES6 module export and import method", the content is detailed, the steps are clear, the details are handled properly, I hope this "node and ES6 module export and import method" article can help you solve your doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge bar.

Export and Import of node

Export syntax for 1.node

Var path = {} module.exports = path

Import syntax for 2.node

Const path = require ('path')

Export and Import of ES6

Export syntax for 1.ES6

Export default {} (only one member can be exposed) export var s = {} export var b = {} (multiple members can be exposed)

Import syntax for 2.ES6

Import a from 'package name (or file path)' (import export default leak members) import {s} from 'package name (or file path)' (import export leak members with the same name)

Examples add:

/ / ordinary export export {name:'zs', age: 20} / / the exported module defaults to the user's name, and can only be exported once using default. Other modules exported by export default {name:'zs', age: 20} / / export var title = "Little Star" export var content = "ha"

Import instance

Import {name,age} from'. / test.jsimport M1 from'. / test.jsimport {title,content} from'. / test.js'console.log (M1) console.log (title+ "-" + content) here, this article "methods of module export and import in node and ES6" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Module member grammar method article content instance file path proper normal consistent user name multiple small star idea new knowledge more step Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Redmi Shulou Technology Xiaomi