RealTime CRUD Application with nodejs /express and mongodb - node.js

I wish to create a realtime crud application, using node.js and express as the backend with MongoDB as the database in order to serve flutter frontend
I tried searching on google and GitHub, I found socket.io, but just for chat applications. my goal is to make a mobile app with synchronized data (like apps using firebase) using node js and MongoDB as Backend. Thank you!

Socket.Io is a good option for real-time communication. In fact it is a very popular choice. Socket.IO is not created to build chat application. Most of the time, as an example of real-time app everyone bring the concept of chatting. Main purpose of Socket.IO is to transfer data in real-time. It can be any data.
If you are new to this world then I would suggest you to take a look at FeathersJS. You can switch from REST to Real-time or vice versa anytime you want with a couple of lines of code change. A lot of things are hidden from you to make your development easier. Their documentation is good as well.
And the fun part is, FeathersJS is based on ExpressJS and you can choose database driver as you want (mongoose is available as an option).

Related

What technologies would necessary to connect to a cloud server from a Node.js backend?

I am relatively new to mobile development and would like to know further information about this specific topic.
I am working on a React Native based mobile application and am now getting around to implementing the back-end for this application. I will need to send data back and forth from the client (the mobile application) to the server (a cloud server). I am aware I can accomplish this with technologies such as a MongoDB database or a Firebase database, however, I would like to try to implement this on a personal cloud server.
How would I go about establishing a connection to a server in node.js so that I may send and receive data?
Thus far, I have looked the node library Express.js, but I am unsure if this is of any relevance as to what I am looking for in terms of a solution to what I am trying to achieve.
First of all, I think you need to have a backend project for making your backend you choose Nodejs
Node JS is a fast JavaScript runtime environment that we use to build server-side applications, but it does not know how to perform serving files, handling requests, and handling HTTP methods, so this is where express js comes in.
Express JS is a Node.js framework designed to build API's web applications cross-platform mobile apps quickly and make node js easy.
Why Express JS?
Express was created to make APIs and web applications with ease
It saves a lot of coding time almost by half and still makes web and
mobile applications are efficient.
The reason behind creating an express framework for node js is:
Time-efficient
Fast
Economical
Easy to learn
Asynchronous
After completing your backend project with either postgres or mongodb database connection and node js you can deploy it to your cloud server and access it from the apis form the front end mobile or web applications.
Another thing I want to mention you can also create some web pages using node handlebars as well.

Best technology to implement semi realtime leader board (app: React-Native, backend: NestJS- Mongo)

I am looking for suggestions how to best implement a semi-realtime leaderboard. I have implemented an app in React Native and for the backend I am using NestJS with MongoDB. The app uses Mongo to store several performance metrics generated by the app. In the app I want to show a top-x ranking of the performance metrics from all clients. What is the best way to notify the app that the ranking has been updated by a different client. I don’t need an instant response like a chat app, a refresh interval of lets say 10sec is sufficient. For this phase of the project there will be less than 10k clients. I prefer I can keep using the nestJS-Mongo backend.
I am fairly new to the world of app programming. I tried to find suitable solution online but want to know how this is normally done.

Meteor - Can I develop the back-end first, and after backend is done, develop front-end?

My team has developed an iOS and Android App for our project while we use node and socket.io for back-end. We want to move to meteor so we can have a front-end with Angular 2 easily connected with the back-end.
But we want to rewrite the back-end with Meteor so our Apps can use it. And after this create the front-end.
My question is easy, in Meteor front-end and back-end are done at the same time? Or can we first build the back-end and after this the front-end?
Yes, this is possible although it would feel a bit awkward to an experienced Meteor developer.
The Meteor "back-end" exposes the following:
managed collections: these are the definitions of the mongodb collections that will be used by your app to persist data. Note that some of these can be private to the back end, i.e. not exposed to the front end at all.
publications: these are the filtered/projected "views" of the collection data that the back-end will share with the front end on request (the form of the request is a subscription). Published data is synchronized bidirectionally with the front end asynchronously over WebSocket. This is the magic of Meteor's DDP which IMO is Meteor's core innovation.
methods: these follow a more traditional request-response pattern. You can have as many of these as you want and each can accept any number of parameters including objects. Meteor can also do latency compensation for methods which means that the method is first simulated on the client and the UI updated while waiting for the server to come back with an authoritative result. If the server result differs then the UI is patched up with the authoritative result. This makes database updates appear instantaneous to the user while providing eventual consistency.
If you like you can even build traditional REST endpoints with Meteor but then you would be missing out on the reactive sugar. These can of course be useful for other integrations however.
Like nodejs, Meteor encourages developers to tackle the full-stack. You're less likely to segregate developers into back-end and front-end functions which gives you a lot more flexibility.

How to write to Meteor database from external application?

I'm trying to figure out how to insert data into a Meteor mongodb database from an external native mobile application that I'm writing (specifically for iOS using Cinder, right now). I'd like events that happen on the mobile device application to be written to my Meteor app's database, so that it can be immediately displayed on a browser elsewhere.
Importantly, I need to stay in my native application on the mobile device - I can't launch into a browser. I'm a bit new to Meteor, so apologies if I'm overlooking something obvious.
Any ideas on how to do this?
Thanks!
Your best bet is to use an iOS DDP client like this one. You can use this client natively in your existing iOS app and subscribe and write back to data in your Meteor ecosystem.
DDP stands for Distributed Data Protocol and is authored by the Meteor group as an external standard for real-time app frameworks to adopt. It's a much preferred method than communicating directly with the database because you can leverage the publish and subscribe methods within the Meteor ecosystem.
The protocol is under rapid development.
I believe there will be a release shortly that will expound on the current state of DDP and the evolution of its official specification. An official spec is slated for the 1.0 release.
Note: Here is a great video overview of DDP in its present form.
Another option is to have your iOS app write directly to the MongoDB instance used by your Meteor app. You can use any MongoDB driver such as NuMongoDB. Meteor polls the MongoDB database every ten seconds so web based users will automatically see updates, albeit with a short lag.
DDP is evolving quickly, as Tim mentioned, so this option might be a little more stable.
In terms of hosting, for scalability I recommend separating your MongoDB instance from the free meteor.com site, by using a Mongo host such as MongoHQ.
And what about other cases ?
I mean browser applications ?

Node.js and Socket.io - how far can they go with real time web applications?

I am going to build a web application to manage notes (think of something similar to Evernote). I have decided to use Backbone.js+JQuery client side.
Server-side, I haven't decided yet: either pure PHP (that I know very well) or Node.js+Socket.io (completely new to me).
I am considering Node.js+Socket.io because I would like to have my web application being real-time (i.e: if a user updates a note, that note gets updated instantly for a collaborator who shares that note, without reloading the page).
I was also considering, as a third alternative, to use Node.js and Socket.io for the UI and PHP for the REST API (I feel more comfortable to build an API with PHP). The PHP and Javascript code will share the MongoDB database.
My question is this: if I develop the REST API for my web application with PHP and a new note for the user gets created through the API (i.e.: the Android app sends an API request to create that note), will Node.js, Socket.it and Backbone.js be able to instantly update the UI of the user and show the new note on their screen? I think that can be called "push notification".
I hope I was clear enough.
Also, is there any alternative outstanding technology to build real time web applications?
Yes Node.js + Socket.IO will do a very good job of this. Node uses an event-loop, this means upon a request it is entered into a queue. Node deals with these requests one-by-one. Traditional web servers deal with a 'Thread-per-request' approach where a thread is created to handle that requests.
The benefit of Node here is that it doesn't need to context switch so often, this means it can deal with these requests very quickly... most likely faster than your PHP server. However Node runs as a single process, on a single CPU core. If your application is CPU intensive it could be that it blocks, meaning the time for each requests will be slower.
However it sounds to me like your application isn't CPU intensive, meaning Node.js will work well.
Decision
If your time is limited, and you don't want to learn a new skill (Node), PHP will be fine. If you have the time I recommend learning Node.js, as it is very strong when it comes to I/O intensive tasks such as a REST API for creating Notes.
Updating the UI
If your intended use is through a mobile device, I recommend using WebSockets but having a fallback such as long-polling. It is possible to update the Client UI using either Node or PHP. However from my experience it is much easier to do so using Socket.IO on Node.js.
Example Updating the client using Node.js / Socket.io
Client-side
socket.on('new-note', function (data) {
placeNewNote(data);
});
Server-side
socket.emit('new-note', data);
Getting Started With Node:
How do I get started with Node.js
Please also note, if you want to build a native Android mobile app which uses WebSockets... you will need to use: Java socket.io client
Using Node.js for both web server and push server is of course the best way. Especially since if you are going to use Node.js anyway then you have to learn it, so learning how to make a web server is only natural (I advice using the most famous Express framework).
Now you can use PHP for web server and Node.js for push server. To make them communicate with each other you would probably want to add Redis to your application. Redis will allow you to push notifications to any client connected to it, like PHP server or Node.js push server (and it scales well). From that point push server will push the data further to the client's browser.
Alternative technology would be for example Twisted server. Of course you'll need to learn Python in order to use it. And I don't know whether it supports WebSockets correctly. I think you should stick with Node.js + socket.io.

Resources