This article is a mirror article of machine translation, please click here to jump to the original article.

View: 9025|Reply: 0

node.js modular interface

[Copy link]
Posted on 10/5/2016 8:22:27 PM | | | |

In nodejs, two objects are provided, exports and require, where exports is the interface exposed by the module, and require is used to obtain the interface of a module from the outside, that is, the exports object of the obtained module. In the interface thrown by exports, if you want your module to be a special object type, use module.exports, if you want the module to be a traditional module instance, use the exports.xx method, module.exports is the real interface, and exports is just an auxiliary tool. In the end, it is module.exports that is returned to the call, not exports.


The demo is very simple, that is, to create an http service, and then, if you want to implement it modularly, you don't want to write it in a file.

test.js file code:



server.js file code:



We just run it test.js node!!!

Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply





Previous:Why can't you do without Stackoverflow?
Next:LNMP one-click installation package stable version download
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com