In previous part of the tutorial we made simple node.js API sending a hardcoded json containing a message string to the Android client. Now , we will be adding say EMPLOYEE details using one API ( addEmployee ) into the Mongodb and retrieving the list using other API ( listEmployee ). Mongodb is document-based, high-performance NoSQL database. You can define multiple databases in MongoDB where each database can have many collections (like TABLE ), and those collections are simply a set of documents that consist of data stored as a key-value pair. i) In terminal , enter npm install mongodb --save that will download mongodb module locally and creates a directory mongodb inside node_modules. Also ,enter npm install body-parser --save that will download body-parser module that allows sending parameters of post requests. We will be modifying the same main.js file created in Part I of the tutorial. Add below lines of code : var express = require('express'); // impo...
We are starting with a tutorial series which will be multi-part consisting creation of a simple Node.js API with MongoDB integration and later will be connecting the API to Android App. i) We will be creating Node.js API and running it locally on localhost. Node.js is basically written in javascript and will be needing a text editor. Will be using Sublime Text 2 which as powerful editing options with more plugins gives good control to code. You should have basic understanding of Node.js and its specific modules like Express. Download latest version of Node.js installable archive file from Node.js Downloads . We will be using Express framework module which gives functionality for HTTP Requests. In terminal , enter npm install express --save that will download express installation locally and creates a directory express inside node_modules. Create a folder NodeExample and inside create file main.js . main.js var express = require('express'); // import...