News for hackers. Stuff that matters.
Re:Why Node.js Is Totally Awesome by zbanks on Tuesday October 12, 2010 @10:03PM (#1785753)
I cringe whenever people bring up point 1.

Just because your front-end uses JS, doesn't mean that the same code runs on the back-end. You still have to write new code.

I guess there are 2 good parts about it, though. For one, you get awesome HTML/XML parsing & traversing out of the box. Which can be nice, I guess.

Also, you get to use some preexisting JS libraries. Underscore is the biggest one that comes to mind. (Does coffeescript work? haven't tried that one) JQuery works theoretically, but it does mostly DOM stuff, which isn't used enough to warrant the huge lib.

Re:Why Node.js Is Totally Awesome by jashkenas on Tuesday October 12, 2010 @10:17PM (#1785785)
Yes, CoffeeScript produces plain-vanilla JavaScript that works fine on both the browser and the server. The CoffeeScript compiler itself also works in any JS runtime...

For an example of what a CoffeeScript/Node app looks like, take a peek at this:

http://github.com/jashkenas/api-playground/blob/master/src/a...

Re:Why Node.js Is Totally Awesome by zbanks on Tuesday October 12, 2010 @10:18PM (#1785786)
Thanks. I assumed it would. Cool link.
Re:Why Node.js Is Totally Awesome by paulbaumgart on Tuesday October 12, 2010 @10:14PM (#1785779)
It depends on how complex your front-end is. As you put more logic on the client-side, the chance of some of that code being useful on the server-side grows.

For example, the Objective-J compiler and loader system ( http://github.com/280north/cappuccino/tree/master/Objective-... ) runs with almost no modification both in the browser-- for on-the-fly compilation during development-- and from the command line-- for pre-compilation prior to deployment. (As an aside it runs on Narwhal, not Node.JS. But the point stands.)

Re:Why Node.js Is Totally Awesome by mcantor on Tuesday October 12, 2010 @10:11PM (#1785772)
Why can't you run the same code...? Can't you at least use the same domain objects?
Re:Why Node.js Is Totally Awesome by WesleyJohnson on Tuesday October 12, 2010 @10:39PM (#1785847)
In theory, you could use the same code provided you wrote it so that it would work independent of it's environment. Realistically, because server-side JavaScript and Node in particular is still new, most people haven't done that. For instance, on the client-side you're probably using XMLHttpRequest to pull in data via a web service. On the server side, you'd likely be fetching that data locally using a server-side library written for node. In that regard, you wouldn't be using the "same" code. However, you could (again, in theory) reuse domain objects and even libraries like YUI or jQuery to load, parse and traverse HTML as well as do server-side event handling as the YUI team has recently demonstrated. http://www.yuiblog.com/blog/2010/04/09/node-js-yui-3-dom-man... - There is a video that goes with that somewhere and I think it was linked on HN recently as well.

OT: Can someone refresh my memory on how to emphasize something on HN?

Re:Why Node.js Is Totally Awesome by mcantor on Tuesday October 12, 2010 @10:54PM (#1785895)
Use asterisks to surround whatever you want italicized. Sometimes, but not always, you can click the little gray "help" next to the input textbox to get such hints.
Re:Why Node.js Is Totally Awesome by cletus on Tuesday October 12, 2010 @11:11PM (#1785950)
While client side and server side validation aren't necessarily the same code, the fact that it's the same language makes it possible. If you have JS on the client and Python on the server you will have to write validation code twice regardless.

So no, it's not a given that you will avoid duplication but possible trumps impossible.