Store Node.js IM App conversations in MongoDB properly - node.js

I'm Developing (yet another) Node,js + Express + Socket.IO Facebook/like Instant Messaging app.
The server-side is mostly complete, but I was looking for a proper way to store and retrieve conversations and I thought I could give MongoDB a try.
I've never worked before with noSQL databases before, so I would like some suggestions on how to deal, mainly, with the writing the proper way.
I was thinking in creating entries containing the user chatting and the chatlines with a timestamp, something simple.
Any thoughts?

Though this does not exactly address the app you are looking to build, 10gen (to company that supports mongodb) has released a video of a presentation walking through the creation of an IRC chat server. This is a very long and very extensive presentation and should cover most of the material that will be relevant for you in building your app. Definitely seems to me like the best resource for you to get started with.
http://www.10gen.com/presentations/mongonyc-2012-building-mongodb-power-chat-server
Hope this helps!

Related

firebase custom user signup

I'm still a newbie in firebase so i might not have the right understanding of this excellent service.
I'm building a blogging mobile app in a client-server architecture in which most if not all the logic are done server-side. all the client does is request and display the result. the client-server communication will be in REST API. and post-processing data then will be pushed to firebase.
keep in mind that this is all still a work in progress and i still don't have an actual working setup yet.
my questions are:
1. is this possible?
2. is this good practice?
a 2nd architecture I'm thinking is to have the client talks with firebase directly and have the nodejs process any events coming from firebase.
same 2 questions as above3. which is better?
mind you i'm also a newbie in nodejs and just start to learn nodejs for this purpose.
Many Thanks in Advance

Ionic app with node.js server

Hello !
A bit of background, I'd want to create my first android/iOS/webapp. The idea is to create a cross platform chat using :
Ionic (and Javascript) for the app
Openshift for the node.js server part
I was going to use Firebase to store the messages, but the free plan just works for 100~ simultaneous users, which ain't a lot ... So I was thinking about creating a node.js server using MongoDB to store everything. Users and messages.
The idea is that I'd get a better server side control on the data, and it seems to be nicer to me.
But is it actually a good idea ?
I'm not sure about the fact that it's pertinent to use a node.js server for that matter, I'm pretty new to those technologies (I'm a Java/COBOL developer)
Thanks in advance !
tl;dr : is storing and processing data for an iOS/Android/Webapp chat with a node.js server is a good idea ?
I think it's a good idea, in few hours you would have a working environment. With Ionic, being web technologies, you can use any library you want, probably the easiest one to use could be socket.io, is simple to use client side and simple server side. You would have rooms and everything already to exchange messages in realtime.
There are a ton of examples for using socket.io to make a chat so should be pretty easy to find infos. ( I made one myself )

Use Socket.IO to update data in real-time?

I am writing a nodejs / express / mongodb based web application and all is working great.
What I've made for learning purposes is a twitter clone.
People can tweet whatever they want and it will show up on their profile and anyone who follows them stream.
On my home page it shows everyone who you are followings posts.
I want this stream to automatically update when someone they are following posts something new.
So they can just sit their on the home page and see all new posts come in in real time.
I've worked with Socket.IO in the past and loved it for it's awesome simplicity of use.
But is Socket.IO an appropriate use for this sort of situation?
Are their better options I can use, perhaps going with a simpler approach of AJAX polling would be more efficient for scalability?
So basically what is the best to use for an application like this?
I need:
Realtime updates to the client
Scalability and effeciency
Thanks!
You have multiple option
My firstoption RacerJS
and Socket.IO
Get data from mongodb and send through racerjs or socket.io
RacerJS is synchronization model built on top of ShareJS, which has underlying technique called Operational Transformation, this is used to do collaborative work on the same data in real-time (like Google docs) I guess it does not really apply to your case or its not the case where it should be used. Because ShareJS does a lot of work to keep clients able to edit at the same time on the same data. This is not the case with Activity streams like your case.
A good option would be Meteor

Offline apps with Node.JS and CouchDB

I have an app that I would like to create. But I am not sure how to go about it. I am using node.js and would like to use couchdb, but if something like mongodb or riak would be a better choice them im willing to hear ideas. But, i have a site, say
cool.com
and on there is a couchdb instance, as well as a site to manage a store. say a shopping cart. the db houses all the store's items and data. The app itself has an admin backend to manage that data and can change items. What i would like to be able to do, is have the ability to have the user be disconnected from the internet, and still have the admin backend work. I realize for this to work I need to use a client side framework with my models/routes/controllers/whatever. But what I am not sure of, is how to let the site function while offline. couchdb if installed locally can sync the data from local to remote when back online, and if the admin user is on the computer, i could have them install couch. but that could be messy.
Also, what if the admin user is on a tablet or a phone? Would I need to have an actual mobile app and a desktop app to do this? is there some way I can set this up so it is seamless the the end user. I would also like this to be offline for end users too, but the bigger audience is the admin.
Another use case, instore POS system. and the power goes out. But the POS system can be loaded from the web onto a tablet and they can still make card based sales if the wifi is out, because the app is available offline.
Im just not sure how to do this. lets assume i need a client framrwork that can handle the data as well as the backend. something like ember, or angular. theres also all in one stacks like meteor and derby js, but those arent fully offline,but are for the appearance of real time. though meteor does have mini mongo so it might be worth looking into.
I was hoping someone could help me figure out how I would get this setup to work, preferrably with couch, but other nosql's would work too if I can have a way to sync the data.
I'm not sure if it would work for you, but I have been thinking of such an application for quite a long time now and been doing some research on what's possible. The best solution I could come up with is using a server with a couchdb and writing the application clientside based. Then for the data storage use pouchdb and synchronize the pouchdb regularly with your serverside couchdb if the app is online. I know pouch is in an early stage and not production ready but if you are willing to put some work into it I'd say it's doable.
If you want clients that work seemless as they go offline and come online (like a POS with the power out) then I would recommend making the app primarily work off local storage with a background publishing or synchronization to the cloud.
Local storage options could be everything from something light like sqlite, sqlexpress, firebird to no sql options like mongo, couchdb etc...
But for the client or device, consider the ease of configuration and weight of the option. You also need to consider the type of clients - do you have many platforms varying from devices to PCs? You don't want something that has a heavy config and runtime footprint. That's fine on the service side.
On the service side, consider the nature of your data and whether it's fitted better for transactional/relational systems (banking etc...) or eventually consistent/non transactional (no-sql) documents. Don't forget hybrid as an option. Also consider the service platform - for example, node goes well with mongodb (json objects front to back) ...
The device and service storage options can be different (and likely should be) separate by service interfaces (soap, rest/http, sockets etc...).
It's hard to have a one size fits all solution but often something light weight like sqlite on the device or client makes for ease of installation/config while scalability on the service side with something like sqlserver/mysql or couchdb/mongodb makes sense.
Some links to read:
http://www.mongodb.org/display/DOCS/Comparing+Mongo+DB+and+Couch+DB
http://www.sqlite.org/
http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx
You're question is pretty wide open and there's no one size fits all solution. Hopefully I provided some options to think about.
There's an interesting project out there called AppJs (http://appjs.com/), which packages Node.JS and Chrominium as a desktop environment. It's currently very fresh (very little documentation), but it appears to be straight forward enough (you'll be using the same tools as you would for your online application).
As for synchronising the offline and online environments. I doubt you can rely on CouchDB in the way that you envisage. CouchDB mobile support is not as comprehensive as some of the documentation suggests. So in this sense, it would be no different to using SQL/Mongo/Punchcards.
You might have more luck with designing a suitable serialisation scheme based on XML or JSON (or just plain text), and passing files between the online and offline installations.
Edit - Since writing this, Node Webkit - http://nwjs.io/ - is clearly the most obvious replacement for App.js. It has a very simple API, and some great features.

Socket.io multiroom chat examples, ready for production

I have written a small site where the main focus is users can create chatrooms for themselves. I've used socket.io and wrote everything myself, trying to get something working.
The site is now out and it turns out my solutions are horribly unreliable. Users complain about messages swallowed, sudden disconnects without notification, some users are logged in 6 times in the same chat, etc etc.
Maybe someone has some example software, open source, that implements a multiroom chat with node.js and socket.io that is ready for production.
I also begin to think that forever start is maybe not the intended way to have a node.js server running.
Have you looked at the available chat source code: http://chat.nodejs.org/ ?
Good place to start.
One of node.js' primary examples is a chat functionality.
You may also check out the modules on github: https://github.com/joyent/node/wiki/modules
There are quite a few frameworks already built for chatrooms.
node-simple-chat is a node.js / socket.io realtime chat.
Or check out Now.js, it also has a guide/example for a chat.
Here you may find a tutorial and sample code to start with - http://blog.denivip.ru/index.php/2012/11/how-to-develop-highload-services-on-node-js/?lang=en
We used socket.io in one project and ended up with custom transport implementation due to some socket.io bugs (sockets management & poor Internet handling).

Resources