How to connect mongoDB to angular2 application?

I have angular2 & mongoDB configured. So far I can read json files using the http service, but I want to develop a complete application that will also have a database connection.

So, I would like to know how to configure the angular2 application so that it can interact with the database.

Any inputs?

Thanks in advance.

+5
source share
2 answers

You should use a framework like ExpressJS to handle interactions with a database that returns JSON data just like you do now with a static file.

There are many tutorials that explain how to do this, for example http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/

Another option you have is to use a framework to do most of the hard work of creating an API. Loopback is a good start for such a task, since they have a generator that can generate client-side code to interact with your API, easier than building everything yourself. I didn't use it at the time, so I'm not sure if they have ng2 as a client-side generator, but this may be a good place to start.

+4
source

You should use server-side infrastructure like hapijs, expressjs etc. where you should establish a connection by specifying your database url like

`MongoDB: // username: password@ds012367.mlab.com : 12367 / DbName

which then connects your application to the database.

0
source

All Articles