Tag:

如何从Node.js中的不同应用程序注入模块

我有两个节点应用程序/服务一起运行,1.主应用程序2.第二个应用程序 主应用程序负责显示来自不同应用程序的所有数据。 现在我把第二个应用程序的一些代码放在主应用程序中,现在它的工作,但我希望它是分离的。 我的意思是说,secnod应用程序的代码将不会在主应用程序(通过某种方式注入运行时) 像第二个服务注册到主应用程序注入它的代码。 它的代码只是两个模块,是否有可能在nodejs中做到这一点? const Socket = require('socket.io-client'); const client = require("./config.json"); module.exports = (serviceRegistry, wsSocket) =>{ var ws = null; var consumer = () => { var registration = serviceRegistry.get("tweets"); console.log("Service: " + registration); //Check if service is online if (registration === null) { if (ws != null) { ws.close(); ws = […]

nodejs模块名称中的“!”字符是做什么的?

我已经开始使用实习库来编写functiontesting,我意识到我不明白这个语法: var assert = require('intern/chai!assert'); var registerSuite = require('intern!object'); 这是什么目的! require()方法的参数中的字符?

如何阻止babel从“this”到“undefined”

编辑 :这不是关于脂肪箭头 。 这也不是传递给一个IIFE 。 这是一个翻译相关的问题。 所以我为我正在开发的一个小应用程序创build了一个简单的pub-sub。 我写在ES6使用传播/rest和保存一些头痛。 我用npm和gulp来设置它,但它却让我发疯。 我做了一个浏览器库,但意识到它可以在任何地方使用,所以我决定让Commonjs和AMD兼容。 这里是我的代码的修剪版本: (function(root, factory) { if(typeof define === 'function' && define.amd) { define([], function() { return (root.simplePubSub = factory()) }); } else if(typeof module === 'object' && module.exports) { module.exports = (root.simplePubSub = factory()) } else { root.simplePubSub = root.SPS = factory() } }(this, function() { […]