ServerJS/FAQ

From MozillaWiki
Jump to: navigation, search

Why use JavaScript on the server?

Using the same language on both the client and server sides allows for code sharing. As the language of the browser, the JavaScript language is in a unique position to enable this sharing. Using JavaScript on the server-side also leverages knowledge of JavaScript.

Why not Perl/PHP/Python/Ruby?

These languages are not in the browser and so cannot share code with the browser (without undue burden on either the developer or browser.)

If sharing code is the objective, then why not compile language X to JavaScript to send to the browser?

Debugging compiled code is not an enjoyable experience. Often, the abstraction layer between language X and JavaScript also has some holes then you end up needing to plug with hand-crafted JS (and not just stock JS, but JS that is designed to interface with that library). By using JavaScript all the way across, there are no such leaks.

Also, there can be some impedance mismatch between the prototype-based object model in JavaScript and the class-based object models of other languages.

Is there a bonus reason to use JavaScript on the server?

Why yes, I'm glad you asked. JavaScript is powering increasingly complex applications in the browser. This has caused browser vendors to work hard on their JavaScript performance. Server side JavaScript has the potential to significantly outperform other common dynamic languages because of this work.