4 ms·
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 n
by zbanks 16y ago
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.
- mcantor 16y agoWhy can't you run the same code...? Can't you at least use the same domain objects?
- WesleyJohnson 16y agoIn 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-manipulation-oh-my/ 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?
- mcantor 16y agoUse 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.
- paulbaumgart 16y agoIt 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-J/ 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.)
- jashkenas 16y agoYes, 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/app.coffee http://github.com/jashkenas/api-playground/blob/master/src/a...
- zbanks 16y agoThanks. I assumed it would. Cool link.
- cletus 16y agoWhile 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.