Reactjs and Mongodb connection - node.js

I have a fundamental question about Reactjs and Mongodb. I want to build a react app which has a "search" feature that shows results from the database. However, I have an issue on understanding how to implement the connection between the react app and the database.
Sorry for the general question. Every help or hint on how to proceed will be appreciated. Thanks in advance.

React is completely back-end agnostic. Which means you would have to implement the connection yourself.
The regular way is, you setup MongoDB and a Node.js server (or whatever back-end you like) then you connect the Node.js server to MongoDB (via MongoDBs JavaScript SDK) and your React client, which runs in the browser to your Node.js server (via HTTP, express framework could help here).
Browser -> Node.js -> MongoDB.
But MongoDB also has a REST interface you could use directly via the browser, like it's mentioned in the following answer:
https://stackoverflow.com/a/16277603/1016383
Would probably be okay for small proof of concepts or experiements,.

Related

Socket io private messages using expressjs nodejs mongoose

I'm struggling with socket.io to make a chat app with the users that are logged in in my app. I followed the beginner course and I could make a private chat app, but the users aren't the ones that are in my database or they have to create a username to connect to the chat app.
In my search I found this one -
Realtime app with Vue, Laravel, Socket.io and Redis (He's making a similar app using Laravel)
I want the exact same app but using nodejs mongoose express.
Can you help me with some references or tutorials?
Here are some resources that might -
Make A Real-Time Chat Room using Node Webkit, Socket.io, and MEAN
Simple Chat Application using NodeJS and Socket.IO
Please start with any of these and be more specific with what extra feature you're trying to implement. (code would be very helpful)
Couldn't understand what do you mean by the users not in database bit.

What is the best framework and difference of nodejs framework

These days I try to develop real time application using nodejs.
That application want to update the dashboard according to api data.
I installed express and faye and try to compare what is the best and what are the differences of that two.
As I know express is a node base framework and faye is a subscriber/publisher based one.
But I think both are almost same and anyone can help me to identify the differences?
What is fast and what can be done using the frameworks like that ?
Thanks in advance.
They are not very comparable. If you want to create a real-time application, you will probably need to use both.
Express is a web framework. You will need it to serve and handle HTTP requests and responses. It will help you handle things like url routing, request/response handling middleware, interfacing with template engines, etc... Express is as fast as you'll get.
Faye is a pub sub messaging system- It will not be capable of handling standard HTTP requests and responses. You may be able to implement a live stream of the data using Faye, however, you will still have the need to serve up your client side application using Express.
I would also look into Socket.io as an alternative to Faye- in addition to Express.

Sails 0.9.4, socket.io, newbie

Just getting started with Sails & Socket.io. I'm following the docs and setup a simple test project here:
https://github.com/timfulmer/sails-sockets
According to the Sails docs, http://sailsjs.org/#!documentation/sockets, socket subscriptions are setup on the first socket call:
socket.get(), socket.post(), etc. are methods available in the client-side SDK included in new Sails projects. In this example, we'll use them to talk to the backend via Socket.io. Please be aware that you can use these methods whether or not you're using CRUD blueprints.
The test project defines a quick model/controller, with CRUD methods. It connects to the socket using socket.get, and receives previously posted model instances correctly.
Posting a new instance using socket.post makes it to the Sails server and creates the new instance. However, the new instance is never sent to the connection created with socket.get. Even when running the page in two different browser tabs.
Also, posting using a GET request from the browser hangs and never returns.
Am I reading the docs incorrectly or making some other newb mistake?
Thanks,
-- Tim
Ok, turned out to be a total newbie error. Sails does not magically call the function passed into socket.get when new messages are emitted. Sails is magic, but not that magic. Turns out one must implement what to do with new messages in assets/js/app.js. Problem between chair and keyboard, sails rocks!
EDIT
Updated the sample project to work with Sails.js + Socket.io + Backbone.js + CORS, with Backbone.js frontend hosted separately (in s3) than the Sails.js backend:
https://github.com/timfulmer/sails-sockets
Lots of little gotchas involved.

share mongodb between nodejs and meteor

I just finished a REST server application in nodejs using express, passport and mongodb
I want to create a meteor app for the LIVE Statistics of that mongodb REST api's , like number of connections, user online etc.
But I can't figure out a way to use custom mongodb with meteor. Basically I want to share the same database with nodejs/express application and meteor.
Is it possible? I am sure it should be, but I can't figure out HOW!
Help please!
Okay, I got here what to do.
While deploying meteor, they have an option to choose the database.
So i created an app on meteor and then deployed it for nodejs
here is how,
meteor bundle myapp.tgz
extracted myapp.tgz and used the command below.
PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp node bundle/main.js
Here is complete doc : http://docs.meteor.com/#deploying

adding web socket chat into existing nodejs app

I've made nodejs application by this template. And now I want to add simple websocket chat.
My question is: do I have to completely rewrite that application to add websocket chat or I can to save that structure?
You can create a chat using Socket.IO (or another library), it's perfectly possible (and probably a best practice even) to separate the two: the regular server and the WebSocket server.
The two aren't tied together.
I have never used the express MVC template, but socket.io does not use express routes and from my experience they exist side by side just fine. Just add your socket.io server code to app.js to test it out and you can use the client side code within any of your express views.
This assumes you're using socket.io of course. I have no experience with other methods of using websockets with node.js.

Resources