简体   繁体   中英

Building a node.js chat

I'm currently building a web chat with node.js for the backend. It uses web sockets for the communication between server and client. I haven't worked with node before and I always used PHP/MySQL and Ajax to store and retrieve data. The chat can be compared to MSN etc. with user accounts and contact lists. I was looking for some tips and frameworks, which could help me with developing a website which heavily relies on JavaScript and which does all its communication via node.js.

  • What would you recommend to store the data? Mongo db (mongoose? mongo-db native?), SQLite? An easy solution would be appreciated.
  • Would you send everything via the websocket and would you establish a new connection for every conversation?
  • Is there a way to get around PHP completely?
  • Would you recommend the usage Backbone.js or Ember.js?

Thanks for you help!

What would you recommend to store the data? Mongo db (mongoose? mongo-db native?), SQLite? An easy solution would be appreciated.

I would suggest you to use redis , because it is insanely fast .

> Example of benchmark result The test was done with 50 simultaneous
> clients performing 100000 requests. The value SET and GET is a 256
> bytes string. The Linux box is running Linux 2.6, it's Xeon X3320 2.5
> GHz. Text executed using the loopback interface (127.0.0.1). Results:
> about 110000 SETs per second, about 81000 GETs per second.

As client I would use node_redis

Would you send everything via the websocket and would you establish a new connection for every conversation?

websockets are not yet support by every browser(pointing especially to Internet Explorer ;)). I think you should use socket.io which supports multiple transports so that it will work in every major browser.

Is there a way to get around PHP completely?

You could get around PHP completely. Use for example express as your web framework instead of PHP

Would you recommend the usage Backbone.js or Ember.js?

Also need to have a better look at both of them.

  • Use mongo-db or couchDB to store the data.
  • Establishing a new connection is better than sending everything through websockets and parsing them.
  • Yes. Use node.js on the server side.
  • You can try either one of them. Both have their pros & cons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM