Examples of CoffeeScript in NodeJS? - node.js

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:
https://github.com/stephank/orona (Game)
https://github.com/drewlesueur/simple-websocket (WebSockets)
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

Related

Is Node.js just used for dev-tooling on the front-end?

For my understanding, node.js is a javascript-engine which is running javascript-code without using a browser(window-global). You can use javascript on a server. But I saw now a lot of tutorials(react, angular, vue etc.). In every tutorial, I have to install something with npm. I can follow there are several dev-tools which I can use on my local machine to minimize my javscript-files or compile sass to css. But in the end, when I put my files on a webserver, I just have normal javascript-files, css-files etc. No node.js code in it, right?
My question is: React, angular, vue.js etc. are written in just normal javascript without node.js right? The reason why I use npm ist just to install every dependencies with one command, right?
A question more: Is there an any recommended order to learn all these frontend-development stuff? There are so much words I have to google it: angular.js, react, vue.js, vanilla.js, typescript, backbone.js, bower, grunt, webpack, yarn etc... I dont know where I start, so I look into few tutorials, but everytime I go through these tutorials, there is a new word(technology) I have to research.
I think you're getting your terminology a little muddled.
Node.js is a JavaScript runtime, built on Google Chrome’s V8 JavaScript engine. However, that is not to say that Node programs are executed in a browser. They aren’t. Rather, the creator of Node (Ryan Dahl) took the V8 engine and enhanced it with various features (such as a file system API and an HTTP library) to create a program we can use to execute JavaScript on our computers.
Node comes bundled with a package manager called npm which you can use to install packages (such as React and Angular) from the npm registry. These packages are indeed written in normal JavaScript (or a language that compiles to JavaScript, such as TypeScript).
The reason why I use npm is just to install every dependencies with one command, right?
Kinda. You can certainly use npm to install dependencies. However, it does a lot more that that. For example you can use npm scripts to carry out various build tasks, or you can create a package yourself and use npm to publish it to the registry.
A question more: Is there an any recommended order to learn all these frontend-development stuff?
As with everything, it depends. What are you trying to build? It's relatively pointless to learn about Node, npm, React and Angular if you are attempting to build a simple static website. If I were you, I'd define a clear goal and set about learning the technologies you'll need to reach that goal. Saying that, if you are doing anything with front-end development, learning about npm will be a good use of your time.
Here's an article by way of further reading that explains things a little more: https://www.sitepoint.com/an-introduction-to-node-js/

Node Js and Express: Where can I find free simple projects to learn and read the code?

I just completed basic tutorial about Nodejs and Express. Where can I find free simple projects to learn and read the code that will cover much of nodejs and express?
Sign up for freecodecamp it's a open source project to learn fullstack Javascript (frontend, data visualization with react.js and backend with node.js and mongodb) it has free tutorials and real world projects to do. Once you complete the all projects you can work on real programming problems for non-profits to build your portfolio.
If you don't know them already, maybe these might be useful:
https://github.com/wercker/getting-started-nodejs
http://amirrajan.net/nodejs-by-example/
Other than that, I am permanently learning tons of stuff by looking at the npm packages in the node_modules folder. Especially by reading the tests.

AngularJS app packaging for autonomous application

I wrote an angularJS app (with nodeJS and ExpressJS as my server). My app is totally independent from the server (I used pouchDB for the data). I would like to create an app/package that can be run from a computer or tablet. How can I do that?
I'm sure there are already lot of questions/answers about this topic but I couldn't find the right solution so I apologize in advance!
Thanks
If you r looking for an full-stack framework, i can really recommend Ionic.
It is a framework, that contains it's own customizable ui-framework(build on sass bootstrap), it is build on cordova aka phonegap and makes it easy to deploy and test the code on android, ios, ... . It is also optimized for angularjs and offers for most functions a directive.
I really love it. I did write a blogpost in german: kkonstantin/ionic
Maybe take your existing frontend javascript code and make use of a css framework, to make it look great for all window sizes.
Like: Ratchet (build on bootstrap)
Then you just make use of Phonegap to deploy your html/css/javascript code to the plattforms.

Yeoman and ExpressJS

I want to know if there is some boilerplate code to use a frontend workflow tool like Yeoman with a backend framework like ExpressJS, if I want to maintain the same codebase for both the front and back ends.
Basically I want to know -
How do the boilerplate code produced by yeoman and express fit in together. Is there a way to integrate the two? (How does the gruntfile fit into the express project)
Can I substitute yeoman's default watch with an express server which reloads pages on update?
Yeoman is currently focused on front-end app development, but we're going to explore back-end integration in the future.
No, actually there isn't any right now.
But you can combine express.js with the component package manager. There is some work left, and you cant use yeoman components in component.
To answer your questions
You can look for components in the component repo that you have used in yeoman. Not the same, but might be a solution.
Use the module supervisor for this. You can get it via npm
I haven't found an easy way of integrating my own Express + H5BP + Angular + Grunt skeletons into Yeoman, and eventually just settled for creating a repo here: https://github.com/ericclemmons/genesis-skeleton
From what I've read, there are projects underway to add express generators, but eventually stacks are going to get complex enough to where you'll have to maintain your own starter app, rather than generating it.
There's an experimental branch with yeoman + express.js G+ Yeoman/Express Article
I found yeoman.js to be very cool for rapid prototyping but does require some ramping up to get used to the various tools it's "opinionated" about. I've decided to go over each of the core tools in some vids that are hopefully helpful: yeoman.js related videos
Yoeman fullstack generator now generates both front end and back end. Other interesting frameworks which do the same are Sails JS and StrongLoop
It is worth noting there is an express-generator project:
official docs
npm page
I am going to give it a go - because I'm folling this tutorial - but other than that I cant comment on its value.

What are the Express.js equivalent of Rails Gems?

Is there some kind of equivalent of Rails "Gems" for express.js? Specifically I'm fishing around for something that can read in RSS feeds efficiently, including the ability to accept poorly formed XML files, but my real question is: where do I even get started looking? (or is Express.js too young to have an extension library?)
A lot of people compare express to ROR, but should, as the author also does compare it to sinatra instead of ROR.
Sinatra is a DSL for quickly creating
web applications in Ruby with minimal
effort
If you haven't already installed npm(probably have to install express?) you should. I think you can compare npm to gem. When searching for rss via http://search.npmjs.org I found the following package which could be useful:
http://search.npmjs.org/#/easyrss
Where to start looking:
http://search.npmjs.org/ rss
https://github.com/ node rss
http://google.com node.js rss
Express.js has modules that can act as middleware to express/connect. Modules such as everyauth and session (which is already bundled with connect) add additional functionality to Express and Connect. Express is built on top of Connect.
Several great modules already included into Connect
A quick primer on how Express uses middleware.
I'm not sure about Express specifically, but I know about Node.js npm command that lets you install Node packages.
Alfred's answer is very good, I just want to point out that you shouldn't think of "Express Gems" just like you shouldn't think of "Rails Gems", but instead think of "Node.js Gems" and "Ruby Gems".
You can compare Ruby with Node (as they are both languages), Sinatra (and perhaps Rails, but not 100%) with Express.js.
So there are packages for Node.js which you can install with npm. Express.js is such a package ("gem"). For more packages search npm
If you are interested in Express.js middleware, look here on the Express wiki page

Resources