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, please Reply
|