How to connect mongoDB to angular2 app? How to connect mongoDB to angular2 app? mongodb mongodb

How to connect mongoDB to angular2 app?


You should utilise a framework such as ExpressJS to handle the interaction with the database which returns JSON data in the same way as you are currently doing with a static file.

There are quite a few tutorials around which explain how to do this such as http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/

The other option you have is to use a framework to do much of the heavy lifting around building the API. Loopback is a good start for such a task as they have a generator which can generate client side code to interact with your API making the implementation much easier than building everything yourself. I haven't used it in a while so I'm not sure if they have ng2 as a client side generator yet, but it might be a good place to start.


You should use a server side framework like hapijs, expressjs etc where you have to make a connection by mentioning your database url like

`mongodb://username:password@ds012367.mlab.com:12367/dbName

which then connects your app to database.