Tag: coffeescript

如何在安装后执行“咖啡”命令?

我按照方向安装了咖啡脚本。 $ npm install http://github.com/jashkenas/coffee-script/tarball/master npm http GET http://github.com/jashkenas/coffee-script/tarball/master npm http 200 http://github.com/jashkenas/coffee-script/tarball/master npm http GET https://registry.npmjs.org/mkdirp npm http 200 https://registry.npmjs.org/mkdirp npm WARN package.json cookie-signature@1.0.0 No repository field. npm WARN package.json fresh@0.1.0 No repository field. npm WARN package.json methods@0.0.1 No repository field. npm WARN package.json range-parser@0.0.4 No repository field. npm WARN package.json send@0.1.0 No repository […]

为什么multipart不会产生closures事件

嗨,我不会处理上传stream自己没有接触磁盘驱动器。 所以,我的自然select是多方面的模块。 我采取了一般的例子,并根据https://npmjs.org/package/multiparty页面的说明我把form.parse改为非callback请求。 在这种情况下,磁盘将不会被触摸。 我的代码如下所示: multiparty = require("multiparty") http = require("http") util = require("util") # show a file upload form http.createServer((req, res) -> if req.url is "/upload" and req.method is "POST" form = new multiparty.Form() form.on 'error', (err) -> console.log "Error received #{err}" form.on 'aborted', -> console.log "Aborted" form.on 'part', (part) -> console.log "Part" form.on […]

JavaScript对象作为长度为1的数组有less量值如何使它们不是数组

我有一个使用xml2js库从XML创build的JS对象。 JS对象具有所有元素作为数组,每个数组中只有一个元素。 如何将其更改为仅具有值而不在数组内。 例如,它看起来像这样:{a:[b],c:[d]}我希望它是像{a:b,c:d}

范围内的变化承诺“那么”方法

我写了下面的程序,每N毫秒处理一个目录中的所有文件: fs = require "fs" Q = require "q" class FileProcessor constructor: (options) -> @dir = options.dir @delay = options.delay processFiles: -> Q.nfcall fs.readdir, @dir .then (files) -> Q.all files.map (file) -> @processFile file # <– Error! .then -> Q.delay @delay .then -> @processFiles() .done() processFile: (file) -> deferred = Q.defer() # Does some stuff. […]

无法将socket.io事件转换为Bacon EventStream

在socket.io上的事件绑定下面工作正常, io = require('socket.io')() io.on 'connection', (socket) -> console.log socket.id io.listen 3000 然后尝试将socket.io event转换为Bacon EventStream , Bacon = require('baconjs').Bacon io = require('socket.io')() connections = Bacon.fromEventTarget io, 'connection' connections.onValue (socket) -> console.log socket.id io.listen 3000 为什么在下面失败? TypeError: Object connection has no method 'on'

咖啡标记重置卡不是一个function

我已经在nodejs上运行了coffeescript和expressjs,我正在制作一个脚本给你9个随机的纸牌(没有重复的),我做了一个函数resetCards在每次显示之后重置卡片,但是当我运行脚本时给我: TypeError: resetCards is not a function at Object.<anonymous> (/home/zunon/projects/xKoot/router.js:10:1) at Module._compile (module.js:398:26) at Object.Module._extensions..js (module.js:405:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object.<anonymous> (/home/zunon/projects/xKoot/xkoot.js:6:10) at Module._compile (module.js:398:26) at Object.Module._extensions..js (module.js:405:10) 这是文件router.coffee: express = require 'express' router = express.Router() cards = [] resetCards() router.route '/randomcard' .get (req, res) -> […]

在nodejs / commonjs中用coffeescript(zappa)重新导出模块(mongoose)

我正在使用mongoose @ 2.0.4,并且想到了将模块中的mongoose.connect()调用整齐地抽象出来。 所以使用nodejs,我期望以下工作: 在myMongoose.coffee : mongoose = require 'mongoose' mongoose.connect 'mongodb://localhost/test' @exports = mongoose 并使用它: MyModel.coffee mongoose = require 'myMongoose' console.log mongoose #Prints massive object (including Schema) Schema = mongoose.Schema console.log Schema # undefined 为什么要像Schema那样访问一个子元素(技术上来说是构造函数,我认为)不起作用? 即使向myMongoose.coffee添加@exports.Schema = mongoose.Schema exports.Schema @exports.Schema = mongoose.Schema mongoose.Schema也不能解决问题。

Node.js范围错误

我收到以下错误: /Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:6 app.get('/login', function(req, res) { ^ ReferenceError: app is not defined at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:6:3) at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/apps/authentication/routes.coffee:15:4) at Module._compile (module.js:449:26) at Object.require.extensions..coffee (/Users/nblavoie/Desktop/HotPie/HotPie/node_modules/coffee-script/lib/coffee-script/coffee-script.js:22:21) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:362:17) at require (module.js:378:17) at Object.<anonymous> (/Users/nblavoie/Desktop/HotPie/HotPie/app.js:31:1) at Module._compile (module.js:449:26) 尝试将(应用)variables传递给以下需要: /** * Module dependencies. */ require('coffee-script'); var express = require('express') , http […]

如何调整while循环中的variables作用域以匹配CoffeeScript中的所有正则expression式?

我在coffeescript循环中遇到了一些麻烦。 原来的function如下, 来源是这个答案 : // Return all pattern matches with captured groups RegExp.prototype.execAll = function(string) { var match = null; var matches = new Array(); while (match = this.exec(string)) { var matchArray = []; for (i in match) { if (parseInt(i) == i) { matchArray.push(match[i]); } } matches.push(matchArray); } return matches; } 它按预期工作。 我已经通过js2coffee转换它,咖啡脚本是: # […]

Node.js服务器GET在使用几个小时后分离API失败

在我的节点站点中,我调用了使用标准http get构build的restful API服务。 经过几个小时的沟通成功的工作,我发现请求停止发送,它只是等待,最终超时。 被调用的API仍然能够很好地接收来自其他地方的请求,但是当从站点发送请求时,它不会到达API。 我已经尝试了stream.pipe,util.pump,只是将文件写入文件系统。 我正在使用节点0.6.15。 我的网站和被调用的服务在同一台服务器上,所以正在调用localhost。 内存占用率大约为25%,CPU平均使用率约为10%。 一段时间后,我开始使用请求模块,但我得到相同的行为。 在失败varrys之前,它调用的数量似乎在5到100之间。最后,我必须重新启动站点,但不是API再次使其工作。 这里大概是什么在网站的代码看起来像: var Request = require('request'); downloadPDF: function(req, res) { Project.findById(req.params.Project_id, function(err, project) { project.findDoc(req.params.doc_id ,function(err, doc) { var pdfileName; pdfileName = doc.name + ".pdf"; res.contentType(pdfileName); res.header('Content-Disposition', "filename=" + pdfileName); Request("http://localhost:3001/" + project._id).pipe(res); }); }); } 我有很多可能发生的事情。