简体   繁体   English

如何将此代码放在外部文件中?

[英]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.

相关问题 我可以将jsp特定的代码放在外部脚本文件中吗 - Can I put jsp specific code in an external script file 如何将jQuery代码放在WordPress主题的外部文件中? - How do I put jQuery code in an external file in WordPress theme? 如何将jQuery代码放在外部.js文件中? - How do I put this jQuery code in an external .js file? 如何将代码 thymeleaf 放在外部 javascript 文件中? - How to put code thymeleaf in an external javascript file? 如何包含包含coldfusion代码的外部javascript文件? - How can I include an external javascript file that contains coldfusion code? 如何在具有 twig 元素的外部文件中使用 javascript 代码? - How can I use javascript code in an external file with twig elements? 在AJAX更新中,如何从外部javascript文件访问代码? - In an AJAX update, how can I access code from an external javascript file? 如何让我的图像替换 javascript 代码以在 external.js 文件中工作 - How can I get my image replacing javascript code to work in an external .js file 如何在使用 GatsbyJS 从 Markdown 呈现的页面上运行外部文件中的代码? - How can I run code from an external file on a page rendered from markdown using GatsbyJS? 我可以将Google分析放在外部JS吗? - Can I put Google analytics in external JS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM