简体   繁体   English

如何在流星中访问npm包事件发射器客户端

[英]How to access npm package event emitter client side in meteor

I think this is pretty basic but am having trouble finding a solution. 我认为这是非常基本的,但是很难找到解决方案。 I have found an NPM package LOG-WATCHER (example only) that monitors a specific log file on a clients local file system. 我找到了一个N​​PM软件包LOG-WATCHER(仅用于示例),该软件包监视客户端本地文件系统上的特定日志文件。 LOG-WATCHER emits events 'START', 'ACTION', 'END'. LOG-WATCHER发出事件“ START”,“ ACTION”,“ END”。 Since this file is client only I am using browserify. 由于此文件仅是客户端,因此我正在使用browserify。 In my packages.json I have added "LOG-WATCHER": "1.0" 在我的packages.json中,我添加了"LOG-WATCHER": "1.0"

In /client/lib app.browserify.js I have added logWatcher = require("LOG-WATCHER"); 在/ client / lib app.browserify.js中,我添加了logWatcher = require("LOG-WATCHER");

logWatcher should now be a global variable that I can use in my app. 现在,logWatcher应该是可以在我的应用程序中使用的全局变量。 So my question is how can I access one of the events START/ACTION/END through the logWatcher? 所以我的问题是如何通过logWatcher访问事件START / ACTION / END之一? Very confused on how to put into place. 对如何摆放非常困惑。

npmRequire is a funciton who presume you are on a NodeJs env. npmRequire是一个函数,它假定您在NodeJs环境中。 So you can use it only on Server. 因此,您只能在服务器上使用它。

Using browserify you will be able to create an assert for client. 使用browserify,您将能够为客户端创建一个断言。 Take a look to this two links : - https://react-in-meteor.readthedocs.org/en/latest/meteor-data/ - https://atmospherejs.com/cosmos/browserify 看一下这两个链接: -https : //react-in-meteor.readthedocs.org/en/latest/meteor-data/-https : //atmospherejs.com/cosmos/browserify

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM