admin管理员组文章数量:1023102
I was reading some code of a project to learn node.js then I found this line (debug = require('debug')('api:server')
) which is enclosed in brackets. As I'm new to programming and when I don't know something I just search it on the web, but I couldn't find an answer for this one. If you are going to tell me to search on the web more aggressively then please tell me HOW too.
I was reading some code of a project to learn node.js then I found this line (debug = require('debug')('api:server')
) which is enclosed in brackets. As I'm new to programming and when I don't know something I just search it on the web, but I couldn't find an answer for this one. If you are going to tell me to search on the web more aggressively then please tell me HOW too.
- I would remend that you read the node.js docs: nodejs/en/docs – Chris Herbst Commented Jan 23, 2020 at 6:07
1 Answer
Reset to default 5require
returns the exports of some other module. Here, since debug
is being passed into require
, the debug
module is being required. What this module does is:
debug exposes a function; simply pass this function the name of your module, and it will return a decorated version of console.error for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
So
const debug = require('debug')('api:server');
where require('debug')
resolves to a function, is like:
const debug = deccorateModule('api:server');
where decorateModule
carries out the functionality described above. In this case, require
acts as a higher-order function: a function which returns a function. (You may likely have a module named api:server
)
This results in the debug
variable holding the decorated version of console.error
.
I was reading some code of a project to learn node.js then I found this line (debug = require('debug')('api:server')
) which is enclosed in brackets. As I'm new to programming and when I don't know something I just search it on the web, but I couldn't find an answer for this one. If you are going to tell me to search on the web more aggressively then please tell me HOW too.
I was reading some code of a project to learn node.js then I found this line (debug = require('debug')('api:server')
) which is enclosed in brackets. As I'm new to programming and when I don't know something I just search it on the web, but I couldn't find an answer for this one. If you are going to tell me to search on the web more aggressively then please tell me HOW too.
- I would remend that you read the node.js docs: nodejs/en/docs – Chris Herbst Commented Jan 23, 2020 at 6:07
1 Answer
Reset to default 5require
returns the exports of some other module. Here, since debug
is being passed into require
, the debug
module is being required. What this module does is:
debug exposes a function; simply pass this function the name of your module, and it will return a decorated version of console.error for you to pass debug statements to. This will allow you to toggle the debug output for different parts of your module as well as the module as a whole.
So
const debug = require('debug')('api:server');
where require('debug')
resolves to a function, is like:
const debug = deccorateModule('api:server');
where decorateModule
carries out the functionality described above. In this case, require
acts as a higher-order function: a function which returns a function. (You may likely have a module named api:server
)
This results in the debug
variable holding the decorated version of console.error
.
本文标签: javascriptwhat does it mean by quotdebugrequire(39debug39)(39apiserver39)quotStack Overflow
版权声明:本文标题:javascript - what does it mean by "debug = require('debug')('api:server')" - S 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745583010a2157418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论