Tag: coffeescript

NodeJS + CoffeeScript,根据请求渲染coffeescript编译的js

我想要做的是添加以下给我已经运行咖啡书面服务器 app.get '/test.js', (req, res) -> render coffee somecoffeefile.coffee 像NodeJS,Express和Coffeescript这样的可能吗? 谢谢! 何塞

TypeScript或CoffeeScript

开始使用node.js来构buildWeb应用程序。 我的一位同事询问了TypeScript,它是微软的一种新语言。 我们计划使用node.js和TypeScript作为脚本引擎来启动我们的新Web应用程序。 我只是想知道是否适合使用TypeScript开发应用程序? TypeScript的未来如何?

环境检测:node.js或浏览器

我正在开发一个需要在客户端和服务器端工作的JS应用(在浏览器和Node.js中使用Javascript),我希望能够重用代码的部分用于双方。 我发现window是一个只能在浏览器上访问的variables,而在节点上是global的,所以我可以检测代码在哪个环境中执行(假设没有脚本声明windowvariables) 他们是两个问题。 我应该如何检测代码在哪个浏览器上运行。 例如,这个代码是否可以。 (这段代码是内联的,这意味着它被一些全局代码包围着,可以在两种环境中重用) if window? totalPath= "../examples/#{path}" else totalPath= "../../examples/#{path}" 我如何在两个环境中使用全局variables? 现在,我正在做下面的事情,但这真的不对。 if window? window.DocUtils = {} window.docX = [] window.docXData= [] else global.DocUtils= {} global.docX = [] global.docXData = []

使用Yeoman和Mocha进行NodeJS和客户端的全面集成testing

我有很好的与Yeoman一起运行的客户端testing。 Yeoman编译我的CoffeeScript,在服务器上打开testing页面,使用PhantomJS访问它,并将所有testing结果传递到命令行。 这个过程相当不好,testing结果通过alert()消息传递给Phantom进程,Phantom进程创build一个临时文件,并将消息填充为JSON。 Yeoman(well,Grunt)遍历临时文件,parsingtesting并将其显示在命令行中。 我解释过程的原因是我想添加一些东西。 我也有服务器端testing。 他们使用mocha和supertest检查API端点和Redis客户端,以确保数据库状态符合预期。 但我想合并这两个testing套件! 我不想为服务器调用写客户端模拟响应。 我不想发送服务器模拟数据。 一路上我会换服务器或客户端,testing不会失败。 我想做一个真正的集成testing。 因此,无论何时在客户端testing完成,我想要一个钩子在服务器端运行相关的testing(检查数据库状态,会话状态,移动到不同的testing页面)。 有没有解决办法? 或者说,从哪里开始对Yeoman / Grunt / grunt-mocha进行黑客攻击? 我觉得grunt-mocha里的Phantom Handlers是一个很好的开始: // Handle methods passed from PhantomJS, including Mocha hooks. var phantomHandlers = { // Mocha hooks. suiteStart: function(name) { unfinished[name] = true; currentModule = name; }, suiteDone: function(name, failed, passed, total) { delete unfinished[name]; […]

咕噜不能find模块'咖啡脚本'

我使用下面的命令来安装平均堆栈并创build一个应用程序: > sudo npm install -g meanio@latest // Get the mean cmdline > mean init myApp // create your first app > cd myApp && npm install // Install dependencies > grunt // Launch mean 但是当我到达最后的咕噜声命令时,我得到错误: module.js:333 throw err; ^ Error: Cannot find module 'coffee-script' at Function.Module._resolveFilename (module.js:331:15) at Function.Module._load (module.js:273:25) at Module.require (module.js:357:17) at […]

我可以直接从node.js运行.coffee文件吗?

我正在做一些教程,我正在用CoffeeScript编写所有的东西。 然后我必须编译为JS,然后在node.js中执行。 有没有办法直接做到这一点?

扩展Node.js类时的大括号

为什么在扩展一个Node.js类的时候,我们将variables包裹在花括号中,如{EventEmitter} = require 'events' ? 例如,Trevor Burnham在他的Event-Driven CoffeeScript 教程中 ,以这种方式扩展了Node的EventEmitter: {EventEmitter} = require 'events' class Rooster extends EventEmitter constructor: -> @on 'wake', -> console.log 'COCKADOODLEDOO!' (foghorn = new Rooster).emit 'wake' # COCKADOODLEDOO!

phantomjs可以使用node.js吗?

我想在我的node.js脚本中使用phantomjs。 有一个phantomjs节点库..但不幸的是作者使用这个怪异的咖啡脚本代码来解释他在做什么: phantom = require 'phantom' phantom.create (ph) -> ph.createPage (page) -> page.open "http://www.google.com", (status) -> console.log "opened google? ", status page.evaluate (-> document.title), (result) -> console.log 'Page title is ' + result ph.exit() 现在如果我直接用javascript来使用phantomjs,它会看起来像这样 : var page = require('webpage').create(); page.open(url, function (status) { var title = page.evaluate(function () { return document.title; }); console.log('Page title […]

将CoffeeScript项目转换为JavaScript(无缩小)?

我们正在使用一个用CoffeeScript @ work编写的特定的jQuery 插件 ,我非常希望能够把这个项目转换成一些看起来很正常的JS。 图书馆看起来好像是很好的结构(好的面向对象的做法,我想),但是如果我能够探索它的源代码,而不必学习CoffeeScript所需的所有技巧,我真的很喜欢它。

ipython相当于javascript / coffeescript为node.js?

更具体地说,是否有REPL有更多的丰富多彩的输出,漂亮的打印,选项卡完成和ipython对node.js javascript / coffeescript的其他好处?