Why use JavaScript rather than PHP on the server?
scriptol.com
scriptol.com
http://devzone.zend.com/1435/wrapping-c-classes-in-a-php-ext...
The use of client-side JavaScript is uncontroversial - most anybody who is targeting the web browser as their client platform will choose to use JavaScript to implement the client user interface and logic. Many client applications which required plugins or native code can now be implemented in JavaScript using advanced HTML5 features.
I presume your question is actually… why server-side JavaScript?
One language, one toolset
The use of a single platform on the client and server means that developer skills will transfer more easily from client to server work. This can lead to more consistent project quality and easier developer scheduling.
DOM and library portability
By using JavaScript everywhere, it is possible to have the same functions on both the client and server, and to run them "close to the data" to avoid unnecessary latency and bandwidth costs. Using libraries like jsdom, it is even possible to write DOM manipulation code on the server, so that more capable clients can render the UI on the client while backwards-compatibility (with IE6, for example) is maintained through server-side rendering.
Node.js and asynchronicity
The use of server-side JavaScript is still quite new, however, and the critical development there is node.js. By using node.js, developers can implement fast, JIT-compiled, garbage-collected server logic, with libraries that enforce asynchronicity. Asynchronous servers are (usually) able to deliver more application throughput than threaded servers on the same hardware, but asynchronous (or "event-based", or "non-blocking") server programming has traditionally been very difficult and error prone.
JavaScript, by the fact of being a highly dynamic functional language, tends to make writing event-based programs a bit simpler, or at least easier for the average programmer to comprehend.
For more background on event-based server programming, read up on Twisted and libevent, and read the classic papers "Threads: Threat or Menace?", "Why Threads Are a Bad Idea (For Most Purposes)", and "Threads Considered Harmful".
Source : http://www.quora.com/Why-would-someone-want-to-build-an-enti...
If you absolutely want to use JavaScript, then yes, you'll be writing event-driven code using a continuation passing style. JavaScript is probably one of the better languages for doing so, since the language is fundamentally single-threaded, and so virtually everything is asynchronous. The biggest argument for this is that you don't have to worry about synchronization. But please don't imply that event-driven programming is The One Way, or even the right way at all. If you want to scale, then you will eventually need to consider threading of some kind, whether it be the poor man's kind that Python and Node use, spawning multiple processes, or the good kind, fibers that automatically multiplex onto OS threads, as the Go and Haskell runtimes implement. Even the async poster-boy, nginx, does this via its workers.
In my perspective lack of threads is a blessing because it takes this complexity out of the equation.
On the other hand, working with async callbacks also takes training and more careful thought of the bindings and closures.
For me, after 6 months with node, I can say that I like it. It's superfast, ample modules to work with, and javascript is very convenient for working with data.
I'm not sure I'd say that, I talked with a few companies that were doing it in the early 2000s, but it wasn't exactly widespread. I vaguely remember at the time the only interpreter was available for Windows, and maybe not a *NIX-like platform so it wasn't really moving.
note: version 1.0 is from 1994
For one thing, client and server share only a small part of the overall functionality. Usually the database interfacing on the server and the user interfacing on the client will require substantially different code.
For another point, Python, Ruby and even PHP come with a lot of available packages and libraries. Node.js has lots of them too, but generally I prefer Django's API design to be more pleasant to work with than node.js
I have found node and the express framework specifically to be the only tools so far that don't overwhelm me and allows me just hack things together without having to google too much. JavaScripts pleasantly simple syntax, and expresses minimalism let me focus on the important parts of web development like how things fit together on a high level. Eventually, I will go back to learning Ruby and Rails, but for now I am happy to actually be working on things instead of just studying.
So, from my perspective, I like server-side js more than PHP and I think it will continue to grow and improve.
Where in node.js, a vaguely procedural programming pattern is usually adhered to, Twisted uses a lot of objects with state to manage protocols and business logic. Many of these objects will adhere to various pre-defined interfaces within Twisted, especially when they are directly dealing with network protocols.
This means that when you're implementing that new protobuf-based protocol, you will always subclass Protocol or one of the simple Protocol subclasses in twisted.protocols.basic, implementing dataReceived() (or the relevant message-oriented function for your subclass), then create a subclass of Factory to create these protocols, then, when you want to connect, you hook up the Factory to an Endpoint.
"Callback hell" is thus mitigated by the fact that you will typically name every callback as a method on the object, and each callback can be as short as a few lines. You also don't tend to bury yourself 6 layers down waiting for a read; instead, you store a bit of state on the object, and wait for dataReceived() (or your buffer-emptying callback) to be called again.
In cases where it's still hell, for whatever reason, the @defer.inlineCallbacks decorator will help by allowing you to write code like this:
@defer.inlineCallbacks
def foo():
result = yield somethingThatReturnsDeferred()
result2 = yield somethingElse(result)
defer.returnValue(result2)
All in all, my proposal is that node.js's issue isn't that it's too opinionated; it's that it's not opinionated enough, implementing only the base layer of something which needs a lot of opinion to be usable.