Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the two ways to export the node module

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge of what the two ways of node export module are, the content is detailed, and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Node export module in two ways: 1, using exports, this method can be exported by adding attributes, and can export multiple members; 2, using "module.exports", this method can directly export the module by assigning values to "module.exports", only a single member can be exported.

Operating environment of this tutorial: windows10 system, nodejs version 12.19.0, Dell G3 computer.

What are the two ways of node export module

There are two ways to export modules

Exports can export multiple members

Module.exports can only export a single member, and the latter will overwrite the previous

1 、 module.exports

We can export the module directly by assigning a value to module.exports

Module.exports can export individual members

All the functions of exports can be realized by module.exports.

2 、 exports

The exports variable is a reference to module.exports provided by node.

Exports exports by adding attributes, and only one object can be exported.

If you point the exports variable directly to a value, it does not affect module.exports, but this is tantamount to severing the connection between exports and module.exports.

Examples are as follows:

/ / define the method, the constant const myPI = 3.14const add = (a _ r _ b) = > a + b / / Export, any of the two methods can / / method 1: exports.myPI = myPIexports.add = add// method 2: module.exports.myPI = myPImodule.exports.add = add// method 2 (deformation) module.exports = {myPI, add} these are all the contents of this article, "what are the two ways of node export module?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report