Nodejs notes

来源:互联网 发布:mysql emoji 截断 编辑:程序博客网 时间:2024/06/06 20:13

Require

When require is given a path of a folder, nodejs will look for index.js file in that folder. If index.js exists, nodejs uses it. Otherwise it causes an error.

Module.exports and require

module.exports is used to export a module, which exposes methods and properties as interfaces to be called. require is to import a module. Principly, module.exports and require work as below:

module.exports = {    greet: function () { return 0; }}require = function (filepath) {    // interpret the file and return the assigned module.exports    ...    return module.exports;}
原创粉丝点击