Tag: coffeescript

客户端和服务器在同一个nodejs进程中

尝试在同一节点进程中使用客户端和服务器创build回显服务器testing。 如果将代码拆分为2个文件(服务器和客户端),则该代码有效,但如果合并为1个文件则不起作用。 我怎样才能得到它在1文件内工作? var HOST, createServer, g, net; net = require("net"); HOST = "127.0.0.1"; createServer = function(port) { net.createServer(function(sock) { sock.write("welcome! on port " + port + "\r\n"); console.log("CONNECTED: " + sock.remoteAddress + ":" + sock.remotePort); while (true) { sock.write("hello\r\n"); } }).listen(port, HOST); console.log("server listening on " + port); }; createServer(7001); g = net.createConnection(7001, HOST); […]

hubot脚本加载yml文件,不要使用相对path

我正在构build一个hubot脚本,我想在其中加载一个yml文件。 我正在使用yamljs npm包来读取YAML文件。 问题是,它总是说“没有这样的文件或目录”的错误。 如果我把绝对path的作品。 我错过了什么? 我正在像这样加载文件: feeds = YAML.load('../feeds.yml'); 这是我的目录结构:

如何呈现404竖琴作为库的页面

我使用竖琴作为一个Express中间件来呈现我的静态文件,我写作玉/咖啡/手写笔。 一切工作正常,除了当我浏览一个不存在的页面。 而不是通常的404页面,我迎接一个普通的“无法GET /(页面名称)”。 如果我用“竖琴服务器”而不是使用节点运行网站,自然它工作正常。 我觉得这个问题是我必须从服务器内部redirect404页面。 但是,如果我这样做,Express不承认玉的格式。 然后,我必须安装翡翠,并将其用作视图引擎。 另外,如果我使用手写笔,我也必须添加该渲染。 它击败了使用竖琴作为中间件的目的。 任何人都可以提出一个处理自定义404.jade文件的select,就像在竖琴的独立版本? 我的代码: express = require "express" harp = require "harp" app = express() app.use express.static __dirname + "/public" .use harp.mount __dirname + "/public" #the following does not work .use (req,res) -> res.status(404).render __dirname + "/public/404.jade" .listen 3000

SocketIO断开离开套接字侦听

我正在尝试使用SocketIO与Redis Pub / Sub结合来监视我的应用程序中的事件。 到目前为止,我有如下的服务器的东西 io.on 'connection', (socket) -> log.info "Connection established. [Socket: #{socket.id}]" socket.on 'join_room', (roomName) -> log.info "Join room '#{roomName}'. [Socket: #{socket.id}]" socket.join roomName redis.on 'message', (redisChannel, message) -> message = JSON.parse message log.info "Room: #{message.room} – Event: #{message.event} – Message: #{message.message}" io.sockets.in(message.room).emit(message.event, message.message) socket.on 'disconnect', -> log.info "Connection destroyed. [Socket #{socket.id}]" 然后,在客户端,我有 […]

Hubot入门

我只是从github 下载hubot 。 我从\d\projects\hubot运行了npm install ,结果出现错误。 第一个错误可能导致其余的: d:\ projects \ hubot \ node_modules \ hubot-hipchat \ node_modules \ node-xmpp \ node_modules \ node-xmpp-core \ node_modules \ node-stringprep> node“d:\ Program Files \ nodejs \ node_modules \ npm \ bin \ node -gyp-> bin \ …. \ node_modules \ node-gyp \ bin \ node-gyp.js“rebuild gyp ERR! configuration错误gyp […]

尽pipe存在服务,但不注入依赖项

所以我一直在做Angular.js项目一段时间,现在将在竞争中使用,并在一半的时间,我意识到我需要一个插件系统dynamic加载一些必要的代码在运行时。 到目前为止,我发现angular.js并不是很适合在运行时加载服务。 由于代码只能在比赛时间提供给竞争对手,我只能提供一个不成功的例子。 // ex1.coffee mainModule = angular.module('mainModule') mainModule.service('needed', () -> @neededFunc() -> console.log "just an example" return this mainModule.service('ex1', ($injector) -> @loadFile = (u, pluginName) -> $.ajax dataType: "script", url: u, data: null, success: (jqxhr, textStatus) => $injector.invoke([pluginName, (plugin) => plugin.testFunc() error: (jqxhr, textStatus, errorThrown) -> console.log "couldn't find the script" return this // […]

meteorJS获取在服务器发布方法中请求的url

如何获取服务器发布方法中请求的url信息? 可能吗?

async.mapLimit用法来发出多个请求

我有这样的路线: async.mapLimit(urls, 10, getCertificatesFromPage, callback) 其中,urls是一个包含url的数组,getCertificatesFromPage: getCertificatesFromPage = (url, callback) -> request url, (err, res, html) -> $ = cheerio.load(html) allRows = $('div.search-result-shop') objCollector = [] allRows.each () -> links = $(this).find('a') obj = companyName: $(this).find('.companyname').text() pageDetailsUrl: '' link: '' for link in links extractedLink = link.attribs.href if extractedLink.includes('http') obj.link = extractedLink else obj.pageDetailsUrl = […]

MongoDB:$和操作符不能使用Node.JS驱动程序进行批量更新

我正尝试在Node.js中使用MongoDB 3.0.4中的批量更新API 。 奇怪的是,如果使用$and $ne这样的运算符,我会得到下面的错误。 简单的查询虽然工作。 WriteError({"code":9,"index":0,"errmsg":"Unknown modifier: $and","op":{"q":{"$and":[{"id":49689},{"status":{"$ne":4}}]},"u":{"$and":[{"id":49689},{"status":{"$ne":4}}]},"multi":true,"upsert":false}}) 下面是CoffeeScript中的一些testing代码: bulk = db.mongo.collection('route-segments').initializeUnorderedBulkOp() filter = $and: [ { id: 49689 } { status: $ne: 4 } ] # filter = id: segStatus.id # <– this works bulk.find(filter).updateOne(filter, $set: status: 4) bulk.execute (err, result) -> console.log "err = #{err}" 我在Mongo shell中尝试了相同的命令,结果如下: > bulk=c.initializeUnorderedBulkOp() { "nInsertOps" : […]

Node.js JSON.parse创build对象与getter属性

这在很大程度上是一个“我做得对吗/我怎么能做得更好”这样一个话题,最后还有一些具体的问题。 如果您对以下文本有其他build议/评论,即使我没有专门提出这些问题,也可以随时发表评论。 我有一个MySQL表,我的应用程序的用户,以及一组固定列,也有一个文本列包含一个JSONconfiguration对象。 这是为了存储不能存储在单独列中的variablesconfiguration数据,因为它具有不同的每个用户的属性。 在configuration数据上不需要查找/sorting/任何东西,所以我们决定这是最好的方法。 当从我的Node.JS应用程序(运行在节点0.12.4)上查询数据库时,我将JSON文本分配给一个对象,然后使用Object.defineProperty创build一个getter属性,在需要时分析JSONstring数据并添加它的对象。 代码如下所示: user = uid: results[0].uid _c: results[0].user_config # JSON config data as string Object.defineProperty user, 'config', get: -> @c = JSON.parse @_c if not @c? return @c 编辑:上面的代码是Coffeescript,这是(不相上下)对于那些不使用Coffeescript的(近似)Javascript等价物: var user = { uid: results[0].uid, _c: results[0].user_config // JSON config data as string }; Object.defineProperty(user, 'config', { get: function() { […]