Tag: coffeescript

MEAN应用程序中的项目单独页面

我正在用Node,Express,Mongoose和Angular编写应用程序。 我可以在页面上显示所有项目。 我的下一步是为数据库中的项目编写单独的页面,所以我创build了路线: app.get '/products/:product_id', (req, res) -> Product.findById req.params.product_id, (err, product) -> res.send(err) if (err) res.render('product.html', { name: product.name } ) return return 一切都很酷,我可以在product.html中显示名称<%= name%>,但Angular不起作用。 没有“/:product_id”工作。 这是我获得所有产品的途径: app.get '/api/products', (req, res) -> Product.find (err, products) -> if (err) res.send(err) res.json(products); # return all products in JSON format return return 而在前面: $http.get('/api/products') .success (data) -> […]

我怎样才能强制在Coffeescript 1.9使用生成器?

CoffeeScript支持生成器现在,但是,我发现只有你使用yield关键字,那么你的函数将被编译为生成器,这里是我的问题,我用koa写我的代码,而一些中间件我不需要asynchronous逻辑,所以我不CoffeeScript认为这是一个正常的function,但是, koa说: app.use() requires a generator function T ^ T,任何人都有一个解决scheme? 谢谢!

如何sorting内部数组和mongoose中的元素

所以我正在尝试在mongoose中做一个半复杂的查询。 具体如下: Event.findOne({ users: { $elemMatch: { user: someUserId, going: 1 }, sort: {createTime: -1} } } 基本上我想要做的是find一个单一的事件,其用户数组中的用户匹配一个ID并参加。 我有用户数组中的每个用户的多个用户logging,所以我想find最近的一个,做到这一点,我想通过createTimesorting用户数组。 这是错误进入的地方,它只是返回undefined 。 当我不包括sortingfunction时,它工作得很好,有什么办法可以包含它吗? 这是我的Event对象的样子: { _id: 1, endTime: 1429060173865, createTime: 1429051773902, startTime: 1429052973865, description: 'some desc', creator: 2, users: [ { user: 1, status: 1, going: 1, createTime: 1429051773749, _id: 552d997d8e923847306e2c21 }, { user: 1, status: […]

更好的coffeescript解决方法来加载这个node.js模块

我想使用这个node.js模块https://github.com/mlin/node-assert-type 基于文件,申报模块; var ty = require("assert-type"); //https://github.com/mlin/node-assert-type var T = ty.Assert; 在实际操作中,这是行不通的。 出现一些咖啡标记错误。 我必须做出以下解决方法; var cs = require("coffee-script/register");//this line needed to require("assert-type") var ty = require("assert-type"); //https://github.com/mlin/node-assert-type var T = ty.Assert; 要使用这个模块,我不得不使用npm install -g coffeescript来安装npm install -g coffeescript 。 有没有办法省略行var cs = require("coffee-script/register"); ? 毕竟,模块本身在本地使用coffeescript。 我正确的做法吗? 添加一行来为使用coffee-script的node.js模块加载coffeescript是否正常吗?

在编写JavaScript库时,将CoffeeScript和Node.js一起使用最好的方法是什么?

我正在写一个JavaScript库,并希望使用CoffeeScript来保持代码的干净,同时写它,但我也想使用类似的节点主要是为了它的requirefunction。 这个想法是命名空间我的子对象在一个全局对象下,并且每个子对象定义在它们自己的文件中以便于开发。 也许我正在做这个错误的方式,我只需要一个干净的方式来写一个客户端JavaScript库与CoffeeScript? 谢谢! 下面的示例文件结构… ./twtmore.coffee twtmore = a: require('./twtmore/a.coffee').a b: require('./twtmore/b.coffee').b c: require('./twtmore/c.coffee').c ./twtmore/a.coffee class a … exports.a = a

节点+咖啡+ Zappa

我一直在寻找与nodejs最好的框架。 我开始倾向扎帕 。 我正在testing它,一切正常,直到我开始一个新的项目,并重新安装与NPM。 现在任何时候我用它做任何事情,都会抛出这个错误。 这个 require('zappa') -> console.log "Hello World!" 变 TypeError: Cannot read property 'prototype' of undefined at Object.<anonymous> (/home/giodamelio/Projects/node-boilerplate/node_modules/zappa/lib/zappa.js:65:15) at Object.<anonymous> (/home/giodamelio/Projects/node-boilerplate/node_modules/zappa/lib/zappa.js:702:4) at Module._compile (module.js:446:26) at Object..js (module.js:464:10) at Module.load (module.js:353:31) at Function._load (module.js:311:12) at Module.require (module.js:359:17) at require (module.js:375:17) at Object.<anonymous> (/home/giodamelio/Projects/node-boilerplate/src/app.coffee:3:3) at Object.<anonymous> (/home/giodamelio/Projects/node-boilerplate/src/app.coffee:52:4) 发生了什么?

麻烦安装npm

我得到了一个干净的安装在我的苹果与山狮子专业版。 然后安装nodejs自制软件即brew install nodejs ,但现在我不能得到npm安装。 例如。 $ node -v v0.8.6 $ curl -k https://npmjs.org/install.sh | sudo sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7882 100 7882 0 0 11359 0 –:–:– –:–:– –:–:– 13803 那么没有其他事情发生 NPM未安装。

从CoffeeScript调用JavaScript“new”

我正在尝试在CoffeeScript代码中重用JavaScript库(sim.js)。 在sim.js的例子中,有3个文件,“sim-0.26.js”,“buffet_restaurant.js”和“buffet_restaurant.html”这样连接在一起(为了简化,我省去了一些参数): 在“buffet_restaurant.html”里面,有 <script type="text/javascript" src="./buffet_restaurant_files/sim-0.26.js"></script> <script type="text/javascript" src="./buffet_restaurant_files/buffet_restaurant.js"></script> <script type="text/javascript"> $(function () { $("#run_simulation").click(function () { var results = buffetRestaurantSimulation(); … buffetRestaurantSimulation是buffet_restaurant.js中的一个函数。 在buffet_restaurant.js中的代码是这样开始的: function buffetRestaurantSimulation() { var sim = new Sim(); … 其中Sim是在sim-0.26.js中定义的,如下所示: function Sim(){…}; 这个例子运行良好。 我想在node.js的CoffeeScript文件中重复使用“Sim”。 所以我试试这个(从jasmine-node调用): sjs = require "./sim-0.26.js" mysim = new sjs.Sim() 其中sim-0.26.js与testsim.spec.coffee(包含此代码的文件)位于同一目录中。 当我调用这个使用: jasmine-node –coffee ./testsim.spec.coffee 我得到这个: mysim = […]

如何与Hubot运行asynchronousRuby脚本?

我想把我的一个Ruby脚本提供给不是开发人员的团队成员(读“不愿意设置和维护Ruby环境”)。 我们也在团队中使用Hubot 。 到现在为止,我确信你已经猜到了我的问题:“我怎么能写一个可以调用我的Ruby脚本的Hubot脚本(CoffeeScript,也就是JS)? ps:我的脚本需要一段时间才能完成,如果你们有一个关于如何让我的hubot给出一个快速反馈(“我听到你,我要运行你的脚本”)的想法,然后通知我,当脚本是完成(“你的脚本成功完成”),这将是真棒。

如何覆盖参数的默认值?

我有以下function签名: question: (question_id, onComplete, use_redis = true) -> 我假设我可以覆盖use_redis参数为false,但我所尝试的一切还没有奏效。 这是可能的,如果我定义我的onCompletecallback内联? 这就是我对函数的调用: Summaryresults.question 1, (summary) -> answer_data.summary = summary done() 我试过添加几个不同的方法,但没有任何工作。 我是否需要在其他地方定义我的callback函数,然后引用它,而不是定义它内联,以覆盖use_redis ?