Tag: coffeescript

Coffee-Script Nodejs和Mongoose

嘿所有试图使用express和mongoose与nodejs MVC玩。 我有以下代码: mongoose = require 'mongoose' Schema = mongoose.Schema mongoose.connect 'mongodb://localhost/quotes' Quote = new Schema() Quote.add { quote : { type: String, required: true} , rank : Number } quote = new mongoose.model 'Quote', Quote module.exports = index: (req,res, next) -> quote.find {}, (err,docs) -> res.render docs 当我去运行服务器,我收到以下内容: Server started on port 3000 module.js:311 […]

通过NPM安装CoffeeScript时连接错误

在Node.js(版本0.6.19)上使用npm(版本1.1.24),尝试在websense代理后面的PC上的Windows XP(SP3)机器上安装CoffeeScript。 我用下面的命令来安装 npm install -g coffee-script 我得到以下错误日志 info it worked if it ends with ok verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe', verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js', verbose cli 'install', verbose cli '-g', verbose cli 'coffee-script' ] info using npm@1.1.24 info using node@v0.6.19 verbose C:\Program Files\nodejs\\node.exe node symlink verbose config file C:\Documents and Settings\peter.campbell\.npmrc verbose config file […]

当在节点下运行基于摩卡咖啡脚本的testing时,意外的' – >'

我正尝试在Windows下的节点上运行摩卡。 我也决定为什么不扔一些CoffeeScript的乐趣。 describe 'Array', -> describe '#indexOf()', -> it 'should return -1 when not present' -> [1,2,3].indexOf(4).should.equal -1 问题是我遇到了一个错误: C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:51 throw err; ^ Error: In C:\projects\BowlingKata\test\test.coffee, Parse error on line 3: Unexpected '->' at Object.parseError (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:477:11) at Object.parse (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:554:22) at C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:43:20 at Object..coffee (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:19:17) at Module.load (module.js:353:31) 这是我的mocha.opts文件: –reporter spec –ui bdd -r should –compilers […]

在客户端从CoffeeScript渲染JS(在Node.js服务器上)

我怎样才能做这个工作? 这是我的玉档: !!! html head title= title link(rel='stylesheet', href='/stylesheets/style.css') sript(type='text/javascript', src='/javascripts/script.coffee') 我不想在我的项目中使用任何JavaScript,所以我使用node-dev运行app.coffee而不是app.js作为服务器。 它适用于服务器端的咖啡文件,但不适合客户端。 我需要某种可以在飞行中编译咖啡文件的渲染引擎,如触笔中间件: app.use require('stylus').middleware(__dirname + '/public') app.use express.static path.join __dirname, 'public'

Coffeescript / Node.js:如何从对象数组中删除重复的对象?

我怎样才能打开这个对象的数组(有一些重复的对象): items = [ { TYPEID: 150927, NAME: 'Staples', COLOR: 'Silver' }, { TYPEID: 1246007, NAME: 'Pencils', COLOR: 'Yellow' }, { TYPEID: 1246007, NAME: 'Pencils', COLOR: 'Blue' }, { TYPEID: 150927, NAME: 'Staples', COLOR: 'Black' }, { TYPEID: 1248350, NAME: 'Staples', COLOR: 'Black' }, { TYPEID: 1246007, NAME: 'Pencils', COLOR: 'Blue' }, { TYPEID: 150927, […]

如何访问CoffeeScript类中的arguments.callee?

我有以下代码 class Foo a: -> console.log arguments.callee.name b: -> @a() c: -> @a() f = new Foo fb() #=> should output 'b' fc() #=> should output 'c' 问题:我怎样才能得到我class上的调用函数的名字? 这是一个用例 class Something extends Stream foo: -> _helper 'foo', 'a', 'b', 'c' bar: -> _helper 'bar', 'my neighbor totoro' dim: -> _helper 'dim', 1, 2, 3 sum: […]

等待在node.js中满足条件

我写了一个包含以下CoffeScript代码的类: class SomeClass # …lots of other code… runner: -> process.nextTick => if @some_condition @do_something_async() @runner() 它应该做的是等待@some_condition为真。 这基本上工作,但是因为它确实快速循环所有这些会导致大量的资源使用。 我将如何正确地做到这一点?

ReferenceError:t没有定义

我有我的express.js / blade.js模板使用i18next库这个代码index.coffee express = require "express" gzippo = require "gzippo" assets = require "connect-assets" jsPaths = require "connect-assets-jspaths" #stylus = require "stylus" blade = require "blade" i18n = require "i18next" http = require "http" https = require "https" fs = require "fs" json = "" #### Application initialization # Create app instance. app = […]

使用nodejsparsing的顺序需要模块

假设我把foo.js , foo.coffee和foo.json放在同一个目录下,并且我require './foo'从那个位置的另一个(coffeescript)文件中得到require './foo' ,那么哪个规则pipe理哪一个会被加载呢? 一个简短的实验(使用require.resolve './foo' )似乎表明JavaScript文件胜过其他两个。 事实上,看着require.extensions它看起来像 .js在那里被作为第一个项目提到 – 但是,然后,对象属性名称本质上是无序的在javascript中,所以任何名称添加到该属性可能会重新sorting条目 -那可以导致另一个解决令? 只是想知道,因为我找不到任何文件。 它确实变得相关,当你做(也许你不应该) coffee –compile route/to/directory 。

优雅地closures节点expressjs不起作用

我有一个简单的问题。 我试图closures一个expressjs nodejs服务器,以便当前的请求完成他们的回应,新的请求被完全拒绝。 我已经把我的代码直截了当地理解为仅仅是那些枯燥的骨头,这样就可以更容易理解: express = require("express") http = require("http") app = express() app.configure -> app.set "port", process.env.PORT or 3000 app.use app.router ran = false app.get '/testrun', (req, res)-> console.log "received request" if ran res.json shouldnt: 'have gotten here' else ran = true setTimeout -> res.json response: 'fail!' , 8000 console.log 'server closing' server.close() setTimeout […]