Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

closed as primarily opinion-based by Mat, andrewsi, Steven V, innaM, Brandon Wamboldt Jul 22 '13 at 16:30

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Why would you want to replace an already working system with one you don't understand? –  Anigel Jul 22 '13 at 14:13
    
If i wouldn't, i would still code PASCAL –  Sprottenwels Jul 22 '13 at 14:14
2  
You can, I don't see any benifits. You will need various of libraries like node js-db for database and so on –  Royal Bg Jul 22 '13 at 14:16

2 Answers 2

up vote 1 down vote accepted

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

share|improve this answer
    
Impressive good answer, thank you! –  Sprottenwels Jul 22 '13 at 18:37

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.