sobota, 23 listopada 2013

AngularJS example MotoAds with NodeJS and MongoDB

I built MotoAds demo application in AngularJS but it did not have any server layer. Data was read directly from the json files. So I was decided to build the server side services. I know pretty well JEE and relational database, so I could use it. But I want to know something new so I chose NodeJS nad MongoDB. Thanks to this decision I got a full stack JavaScript application. It's incredible to use JavaScript to build the complete application.

Now MotoAds demo application consists of:
  • User interface in AngularJS and Bootstrap with full CRUD operations: add, read, edit and remove adverts.
  • Server service layer was built in NodeJS with RESTful serrvices. To simplify the use of a NodeJS I used ExpressJS.
  • Database: all data except the pictures are stored in MongoDB.
So let's see how to add the CRUD operations in AngularJS with services in NodeJS with MongoDB.

Step 1
We write in services.js access to our RESTful services:
Step 2
Inject services in app.js:
We use the angularjs services in controllers.js:
Step 3
In server.js we create the HTTP server with the RESTful service in NodeJS and ExpressJS. It is also used to host angularjs app:
Step 4
In adverts.js we write some code in NodeJS which allows us to use MongoDB:
We run MongoDB and start our HTTP server (node server.js). Now we are typing in web browser URL http://localhost:3000/#/. In web browser we should see the MotoAds application and we can use CRUD operations.

If you want to run this example on your computer, you can download sources from GitHub.

Any comment would be highly appreciated.

Brak komentarzy: