NodeJS 中的 CoffeeScript 示例?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4582376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Examples of CoffeeScript in NodeJS?
提问by Austin Hyde
As a pet project, I am trying to get familiar with NodeJS and CoffeeScript, and am finding it hard to get the ball rolling.
作为一个宠物项目,我正在尝试熟悉 NodeJS 和 CoffeeScript,但发现很难让球滚动。
I've found plenty of examples of single-file super-simple apps like in CoffeeScript's examples folder, however, none of those really show what a full application would look like. I've also scrounged Google to no avail.
我在 CoffeeScript 的examples 文件夹中找到了大量单文件超级简单应用程序的示例,但是,这些示例都没有真正展示完整应用程序的样子。我也搜索过谷歌无济于事。
Do you have any examples of medium-sized, multi-file CoffeeScript/NodeJS apps I could learn from?
你有任何我可以学习的中型、多文件 CoffeeScript/NodeJS 应用程序的例子吗?
采纳答案by Shripad Krishna
See this gist: https://gist.github.com/652819
请参阅此要点:https: //gist.github.com/652819
Its pretty much an entire NodeJS app using the Express framework, Redis for session storage, Couchdb as the database and written in CoffeeScript. However, you are asking for code organization. That depends from developer to developer. I personally prefer Express. However if you prefer MVC style then see Geddy.
它几乎是一个完整的 NodeJS 应用程序,使用 Express 框架,Redis 用于会话存储,Couchdb 作为数据库并用 CoffeeScript 编写。但是,您要求代码组织。这取决于开发商。我个人更喜欢 Express。但是,如果您更喜欢 MVC 风格,那么请参阅 Geddy。
回答by Ivo Wetzel
GitHub is your friend:
GitHub 是你的朋友:
And if you want even more, take a look at the listing for the Coffee-Script Language. I suppose that 95% of the projects there are related to Node.js at the moment.
如果您想要更多,请查看Coffee-Script Language的清单。我想目前 95% 的项目都与 Node.js 相关。
回答by RandomEtc
The Zappa framework is a coffeescript layer on top of Express, Socket.IO and more. It's quite comprehensive and the examples might contain what you're looking for? https://github.com/mauricemach/zappa/
Zappa 框架是 Express、Socket.IO 等之上的一个 coffeescript 层。它非常全面,示例可能包含您正在寻找的内容?https://github.com/mauricemach/zappa/
回答by balupton
here is a search for github, for everything writtin in coffeescript and description containing the word "node" - returning 300+ entries
这是对 github 的搜索,用于在 coffeescript 和描述中包含“节点”一词的所有内容 - 返回 300 多个条目
回答by yfeldblum
By default, it would be the same as a medium-sized, multi-file JavaScript/NodeJS app.
默认情况下,它与中等大小的多文件 JavaScript/NodeJS 应用程序相同。
Except you would have source files named *.coffee, and you would invoke the CoffeeScript compiler to build your JavaScript NodeJS app.
除非您拥有名为 的源文件*.coffee,并且您将调用 CoffeeScript 编译器来构建您的 JavaScript NodeJS 应用程序。
回答by keyvan
EDIT July 25 2013
编辑 2013 年 7 月 25 日
Sails.js has added CoffeeScript support recently. It's a pretty great framework and will make sense to Rails users right off the bat: http://sailsjs.org/
Sails.js 最近添加了 CoffeeScript 支持。这是一个非常棒的框架,对 Rails 用户来说很有意义:http: //sailsjs.org/
My original answer follows:
我的原答案如下:
Check out https://github.com/pheuter/brunch-socket-soup
查看https://github.com/pheuter/brunch-socket-soup
Description: Brunch.io skeleton featuring socket.io, includes a coffeescript server file
描述:包含 socket.io 的 Brunch.io 框架,包括一个 coffeescript 服务器文件
from the README...
从自述文件...
Make sure to have Brunch.io installed.
确保安装了 Brunch.io。
Prepare the bowl:
准备碗:
brunch new <your-project-name> -s github://pheuter/brunch-socket-soup
brunch new <your-project-name> -s github://pheuter/brunch-socket-soup
Throw in the ingredients:
倒入配料:
npm install
npm install
Serve and take sips:
服务并啜饮:
coffee server.coffee && brunch watch
coffee server.coffee && brunch watch
回答by Alex Gray
I find it helpful to examine existingnode modules which were written in coffee-script, of with which I am ALREADY familiar.
我发现检查我已经熟悉的现有节点模块很有帮助。 coffee-script
Run a quick search of your (globally) installed nodemodules, eg..
快速搜索您的(全局)安装的node模块,例如..
for x in $(echo $NODE_PATH | tr ':' '\n'); { [[ -d $x ]] && ls $x/**/*.coffee; }
for x in $(echo $NODE_PATH | tr ':' '\n'); { [[ -d $x ]] && ls $x/**/*.coffee; }
On my system, I'd take a peek at the results (usually with the shortest paths, and which yield the modules with which I am most comfortable).. such as
在我的系统上,我会看一下结果(通常是最短路径,并且产生我最喜欢的模块)。例如
/usr/local/lib/node_modules/ghfm/src/index.coffee
/usr/local/lib/node_modules/ghfm/src/index.coffee
or
或者
/usr/local/lib/node_modules/ipaddr.js/src/ipaddr.coffee
/usr/local/lib/node_modules/ipaddr.js/src/ipaddr.coffee

