I want to connect mongodb server to android application so that i can send data( which is stored online on mongodb ,not locally) to android user. I want to do it through REST api using node.js but couldn't find a way to do it.
Please help.
First of all it's a bad idea to connect to the Database directly. It is possible, but it'a a bad idea.
It's a much better practice to create a web service backend that your app can connect to. This will allow you to implement the business logic on the server. And additionally, you will be able to use not only Android, but iOS, AngularJS and others as clients too.
Generally the most common rest backend architecture looks something like this:
REST BACKEND
I find this way of development to be modular and very well organized.
In short, the API layer only takes HTTP GET and POST methods, and calls the appropriate functions in the Service layer. The service layer holds all of your business logic and calls the DAO layer, and Dao call anb works with the DB.
There's tons of examples for how to build web services, and it's highly dependent on your language of choice for your web tier. There are also tons of examples for consuming web services on Android. You should look it up.
But whatever language you choose the API -> Service -> Dao -> Database scheme should work fine.
If you don't know where to start take a look at Python Flask or Java Spring as good candidates for developing web services. (I use Spring because there is a ton of great documentation on whatever you may need.)
Hope this helps a bit. Good luck!
Related
I was making a thinking exercise about how could I deploy a chat service like WhatsApp or Slack (just wondering), so people could really use it. You need two main parts, the client software (e.g. the app running on the smartphones), and the server software. So how would you develop the server-side code and make it work?
The first idea that came to me was the classic hosting service, but it cannot be the simple "web hosting service", probably because something like this should be programmed at a lower level and not working with HTTP requests and responses. Maybe using specific server-side technology like Node.js (any other suggestion?) to manage different type of requests at lower level, let's say at the layer where TCP lives, would be a better solution.
So I heard about the Amazon Web Services (AWS), which is not classic hosting, it's a cloud computing service. The problem is that I don't know exactly how this works. Could I deploy a server-side application that works at that low level of networking and also makes requests to databases? Would it be difficult to offer this kinf of service using AWS?.
I would like to hear all your opinions about any aspect of this. Would you use other kinf of technology on the server? What do you think about AWS, and if you would think it's a good option, where can I get some info to learn how to use it?
Server Side Code
You can create a chat service backend using NodeJS + express(or Hapi) to cater input Http Requests.
For Hosting: Cloud servers are pretty available these days and allow you to scale if your app grows with time.
Database:
if you already have your DB available (cool) just use ORMs ( like (Sequelize) which provides easy interaction of Nodejs service with your DB. (I have used MySQL + Sql Server + Oracle)
If not, you can create a new DB (MySql- free on your hosting server (cloud?)
I used Microsoft Azure to host a Nodejs(+ Hapi.js) Backend Service ,to be consumed by my mobile application, over the internet.
Azure gives you $200 free credit which is sufficient for you to try and make your hands dirty with them. There are numerous tutorials available for MS-Azure Api App hosting which will guide you to a successful deployment.
I have not yet explored AWS as of now, but i trust that they will be similar in their learning curves.
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.
I'm planning for an application that is a social media app with service like fiverr is integrated where user can communicate with each other and ask for advise.
Problem: What should be the best technology stack, weather it should be MEAN(Mongo, Express, Angular 2.x, Node) or MEN(Mongo, Express, React, Node).
Also I want it to be a REST web app, so that I can develop mobile apps later. So should I use some NodeJS framework like KeyStone or some generator like generator-meanjs. And what should be the directory structure or architecture for this.
Thanks
Choosing the best technology stack is up to the expertise of the group who would be working together. Since you are mentioning about MEAN I assume that you are well acquainted with Javascript. The answer to your other question of having the REST web app, Mean JS does provide you with the REST APIs (courtesy ExpressJS) while using CRUD module generators, You get that out of the box if you are going with mean.
Though all these utilities will help you get started from scratch in no time it really depends on the business logic of how you would want to capture the work flows. From what I get fiverr service seems to be a kind of free lancing website where one would show case their skill set and get hired. Unfortunately fiverr doesn't seem to be having an API where you can integrate your service.
Edit1: To build a service like fiverr you have to tie in various aspects not just the technology stack. There is business logic which hsa to be defined on what you'd want your app to acheive. For example let's assume you are doing some thing similar to fiverr, You would have to account for eCommerce stuff that would be happening. You would have to have user management built in to your app.(Mean.js does provide a few aspects of this, user signin/signup social media integration). Every thing else depends on what you'd actually want your service to acheive, All the best :)
I have an existing web application. It uses Spring MVC on Tomcat and MySQL at the back end with transactions (multi table updates). I am also using spring security for role based authorization. This is very typical website without any real time notification, chat etc.
Now my client wants to add real time notifications like Facebook, chat module etc. Typically on front end some action will be taken, and all or specific logged in users need to get notified. After receiving notification, I need to update some <div> content. Frequency would be high. (Currently user needs to refresh browser.)
I completed POCs using Node.js/Express and looks like it's easy to accomplish these 2 things with Node.js.
I have 3 options:
Move front end to Node.js and may be Angular.js. Manage form validations / security through Node.js/Angular.js but all database calls are still managed by my old website (in a RESTful manner) as I can reuse my existing stuff. Most of the method calls return to a tile but we can easily convert to return JSON object.
Keep existing website as it is and plug in Node.js into it just for real time notification / chat etc.
Scrap existing website and redo everything including security, transactions using Node.js. There are many posts saying as Node.js is kind of new, not preferable for enterprise application and also this might be too much.
Approach 2 would be my preferred approach as we have expertise in Spring, Node would be completely new for us but I don't know whether it's practical & doable approach, what kind of issues I might be facing. I am also not sure how to integrate Spring MVC running on Tomcat and Node.js together.
Please could anybody help me in deciding, out of the three what's the best way to go? Any other approach which might be easier?
You already have an existing Spring MVC codebase and you can reuse it. However you can go ahead with AngularJS for your front-end technology. Your front-end AngularJS code can talk to your existing Spring MVC via REST api and to NodeJS for real-time features which you plan to develop.
You need to use Socket.io within NodeJS which will provide the features you are looking for.
One major problem you might face is related to session when talking to two different backend stack.
I'm trying to build a website myself but I also want to build a native mobile application that will access the same DB in the future.
What I'm thinking now is using Node.js to build Web Services wrapper for the DB and every DB operation will be executed via web service API. And for the website framework, I'm going to use Rails.
Please let me know whether this is a good architecture or not. I'm not sure whether encapsulate data with Web Services is a good idea. Will there be any performance issue? And if it's feasible, which DB should I use? And can rails communicate with DB via web services?
Thanks a lot!
Update
Why do people down vote this question??
I think you have more technology than needed in your architecture right now.
Personally I would create a REST api on top of the DB (using either node or Rails - both are super easy to do this with and both can use pretty well any db)
Then you can write any number of "apps" for the front end process, whether they are web apps, ios apps, android apps, etc... They will all get their data from your REST api on the backend.
You might even consider writing the front end as a single page app using Angular, Knockout or Backbone, something like that. If you do that with node, your entire stack will essentially be written in javascript. It can get confusing for a newb, but it's super powerful.