[英]How can I put this code in an external file?
I've made a little chat with nodeJS, now i want to put this part of code https://github.com/P-Pariston/nodeChat/blob/698ced0afc77e359a2bd32618baf66a873241816/app.js#L112-402 (in yellow) in an external file called commands.js. 我已经与nodeJS进行了一些聊天,现在我想把这部分代码https://github.com/P-Pariston/nodeChat/blob/698ced0afc77e359a2bd32618baf66a873241816/app.js#L112-402 (黄色)放在外部文件,称为commands.js。
Actually, i've tested this: 实际上,我已经对此进行了测试:
app.js app.js
Command.prototype.parser = require('./commands.js');
commands.js 命令
module.export = function (){...}
It doesn't work, i have: 它不起作用,我有:
"MongoClient is not defined". “未定义MongoClient”。
All modules are not passed in commands.js as i can see (socket.io) 如我所见(socket.io),所有模块均未在commands.js中传递
Thanks for your help ! 谢谢你的帮助 !
It doesn't include the context for MongoClient which has been set with a require at the top of the first set of code (outside the commands file) 它不包括MongoClient的上下文,该上下文已在第一组代码的顶部(在命令文件之外)的顶部设置了require。
MongoClient = require('mongodb').MongoClient, MongoClient = require('mongodb')。MongoClient,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.