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.
Related videos on Youtube
Bhushan Gadekar
#angular #nodejs #docker #elasticsearch #springboot #java #jenkins #linux
Updated on September 14, 2022Comments
-
Bhushan Gadekar over 1 year
I have
angular2 & mongoDB
configured. So far I am able to read json files using http service but I want to develop a complete application which will have database connectivity too.So i would like to know how can I configure my angular2 app so that it can interact with the database.
Any inputs?
Thanks in advance.
-
Arijit about 7 yearsHi Bhushan, I believe till now you have implemented mongo and angular2. I have a small question, by reading the answers below I understood, to implement mongo with angular to I have to run another server, like nodejs or expressjs for connection with mongo/creating a rest service. and the lite server of angular 2 cant handle the connection. Is this correct understanding?
-
-
Raj Bhatia over 7 yearsBut Loopback is not fully open source, I found some license terms here link , can you provide some information on it..?
-
Ian Belcher over 7 yearsThats true @RajBhatia and many commonly used open source projects are the same as far as having licensed products/services. There are parts of the strongloop ecosystem which are licensed such as
slc arc
but the basic loopback framework doesn't requireslc
to operate and connect to databases such as mongo. Most of the licensed parts of strongloop are related to enterprise focused tech such as SQL server and Oracle connectors and management systems for your loopback api's etc.