Adequate Infosoft
In this blog, you will learn to build a single-page application with Angular.js, Node.js, and MongoDB. The following are the technologies that we need to build this single-page application.
Use Angular.js for client-side development to develop Single Page App
Communication between Angular.js and Node.js for Cross-Domain Communication
Node.js use for server-side development
Creating web service with express.js based on Rest
Database- MongoDB
Node.js MongoDB Module Extention (mongojs)
Prerequisite
Install new version of Node.js >http://nodejs.org/download/
Install mongojs for Node.js
Command npm install mongojs
Install express.js for node.js
Command npm install express
We will describe the code here:
Use javascript variables to initialize the express.js in respect of Node.js concept.
The above code shows the initialization of the web server in the application variable.
Here you can connect mongodb database with the help of Node.js mongojs module extension library.
Here we have configured to express.js
We have tested the REST-based web services and tested the code whether express.js.
To obtain all usernames from the user collection, we have made another REST API call and supplied the mongojs query.
Here, we've used REST calling to make a POST request to create a user.
The following code in Angular Controller:
We’ve talked about the Angular app in the above code.
In the code above, we referenced the Angular Controller.
We have taken the users' data model through REST communication and displayed it in HTML using the ng-repeat tag.
The user data model was delivered from REST connection to the node server to be saved in MongoDB using the ng-submit tag.