Considering usage of server-side JavaScript

Recently, i heard alot of JavaScript being used sever-side. Node.js, express.js and similiar stuff are mentioned more and more, but i never had the muse or time to dig deeper into the topic.

Now, as the information flood would not decrease, i can not longer ignore those circumstances.

I wonder about two things:

  • Can i replace my complete, simple PHP backend, which is primary used only for database access, with server-side Javascript

and if yes:

  • are there any benefits of doing so?

and if not:

Why is there such a hype?

The topic seems to be quite complex and not too easy to learn, but as time goes by, i more and more get the feeling that this maybe will be the future of backend coding.

Yes you can replace it.

Main concepts about Node you have to know is being async, second is being event-driven. So if your PHP app just accesses db and serve responses back, node.js would be more efficient in such applications, as would not block idling for response from db, but can process with other requests and so on.

It is not complicated, if you do it. Just go and dive into. Don't ask - prototype. It is the best way to understand if you really need it or not.

I've replaced all my PHP need to node.js, except templating.

Yes you can.

If you are primarily serving data, a more contemporary approach would be to use node.js to implement a restful api . Node.js is particularly suited for this as it inherently works asynchronously - which means each request to the data source (ie the database) inherently does not block while the server is waiting to return, allowing it to punch well above it's weight in terms of being efficient when servicing many requests.

You could use the node modules express.js or restify.js to implement this.

A warning though - node.js is a single threaded application which means some work has to be carried out before is scale able. There are some good solutions for this, such as using Amazon Elastic beanstalk. But as node.js is a relative newcomer many other proposed solutions may need some coaxing to be production ready.

You may find it beneficial to read 'Javascript the good parts' by Douglas Crockford before you begin - something I needed to bring my knowledge of Javascript to a level where I could write quality maintainable code for node.js