سؤال

As a pet project, I am trying to get familiar with NodeJS and CoffeeScript, and am finding it hard to get the ball rolling.

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.

Do you have any examples of medium-sized, multi-file CoffeeScript/NodeJS apps I could learn from?

هل كانت مفيدة؟

المحلول

See this gist: 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.

نصائح أخرى

GitHub is your friend:

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.

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/

here is a search for github, for everything writtin in coffeescript and description containing the word "node" - returning 300+ entries

https://github.com/search?langOverride=&language=CoffeeScript&q=node&repo=&start_value=1&type=Repositories&x=0&y=0

By default, it would be the same as a medium-sized, multi-file JavaScript/NodeJS app.

Except you would have source files named *.coffee, and you would invoke the CoffeeScript compiler to build your JavaScript NodeJS app.

EDIT July 25 2013

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/


My original answer follows:

Check out https://github.com/pheuter/brunch-socket-soup

Description: Brunch.io skeleton featuring socket.io, includes a coffeescript server file

from the README...

Make sure to have Brunch.io installed.

Prepare the bowl:

brunch new <your-project-name> -s github://pheuter/brunch-socket-soup

Throw in the ingredients:

npm install

Serve and take sips:

coffee server.coffee && brunch watch

I find it helpful to examine existing node modules which were written in coffee-script, of with which I am ALREADY familiar.

Run a quick search of your (globally) installed node modules, eg..

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

or

/usr/local/lib/node_modules/ipaddr.js/src/ipaddr.coffee

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top