30

I've build several websites using PHP and mySQL as backend, and believe that I'm fairly familiar with both. However during research for my new website I've come across node.js and mongodb (and socket.io, since the site is gonna contain a chat).

I've decided to use node.js and mongodb to run the chat - but don't know if I should just do the entire site with those two things? Since I'm gonna run a node server anyway should I just run another (seperate) one hosting the website? Or is that an bad idea? - is it stable? I could do the programming in PHP and still be using mongodb - but wouldn't node be way faster?

And another question: I've planned to use ajax to handle all the posts to the page - but since I'm allready using socket.io to the chat - should I do all my post request using that? For the ajax I've planned to use jQuery (also for all frontend effects).

4 Answers 4

15

don't know if I should just do the entire site with those two things?

If you want to learn node.js then there is nothing better than coding it.

Since I'm gonna run a node server anyway should I just run another (seperate) one hosting the website?

You can use existing server and run your node.js app on other free port(o). I think for learning node you don't need to have dedicated machine.

is it stable?

Even versions of node.js are stable releases, however until there is 1.0 with feature freeze there could be breaking changes to its API.

I could do the programming in PHP and still be using mongodb - but wouldn't node be way faster?

It most probably (and definitely) would.

I've planned to use ajax to handle all the posts to the page - but since I'm allready using socket.io to the chat - should I do all my post request using that?

I would recommend stick to MVC model and use express since you can get into lot of time consuming troubles if you would use socket.io for classic stuff. Socket.io is namely for real-time functionality and things related to that.

Sign up to request clarification or add additional context in comments.

5 Comments

Express doesn't offer any MVC. It just offers routing and view engines.
@Raynos: So routing and VIEW engines aren't any part of Model-VIEW-Controller functionality?
@yojimbo7 They are part of MVC. But it's not the MVC model. All it's giving you is some sugar for routing and a powerful templating engine. There are no models and no controllers.
@Raynos: Ok, I corrected the MVC model part. You can use routing as a foundation for controller functionality and models highly depend on persistence system which you choose. That said Express still offers foundation for MVC model.
I wouldn't go that far personally. It offers a way to handle requests and responses at a high level. It's independent from MVC.
12

There are already some solid web frameworks for node.js, in particular check out Express. Here's a really good article outlining some lessons and experiences from building a node.js website:

What it’s like building a real website in Node.js

Regarding your second question, it's probably still best to use AJAX handlers and HTTP with jQuery. I'm not sure that jQuery supports callbacks over raw TCP sockets.

2 Comments

There's no reason you can't use socket.io as a TCP transfer and write your own protocol. You can also upgrade to now and use that for bi-directional RPC. These are all alternatives to ajax. There just not as "familiar".
thanks alot for your answer - I'll definitely check out Express before I start programming!
9

node.js + express + jade + stylus + jQuery is my preferred environment.

Using forever to auto restart the server I've never had any real up-time issues even when I have bugs crashing the server on a regular basis.

As for socket.io + jQuery, they do get along fine, but it's just not as natural as the express + jQuery combo. I'd stick to making ajax calls for most things.

1 Comment

express and socket.io are seperate. Whether you use jQuery or mootools or dojo or YUI on the client is also not relevant. Express is meant to give you routing and view engine control. Where as socket.io allows you to have a TCP bi directional stream between client and server.
3

Node.JS can still be a little wild west like, but its improving. It is a very different model from coding in php, but it is very well suited for a lot of websites. You'll probably want to do the thin server (expose a REST API and your websocket endpoints) with a fatter client using something like BackBone.js to keep interactions clean.

The big win from doing the whole thing in node is that you will not have duplication of code between php and js for dealing with the DB or any other services required by both. Node.JS is also fantastic at handling tons and tons of concurrent requests.

Good Luck

2 Comments

Would you mind telling me about what BackBone.js would do for me? - Sorry I haven't had that much experience with socket programming before now. Actually mostly straight PHP web programming.
client side model view controller. When your models are constantly updating over sockets and such, it is very helpful to decouple that from all the DOM/view manipulation. Working with node and a fat javascript client is quite different from straight PHP (especially if you're not using MVC style frameworks with PHP), but by playing into its strengths and following good development practices, you can create very high quality software.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.