Posts

Showing posts from February, 2018

Introduction To Firebase

Image
What is Firebase? Firebase is a backend platform for building Web, Android and IOS applications. Firebase Features Real-time Database  − Firebase supports JSON data and all users connected to it receive live updates after every change. Authentication  − We can use anonymous, password or different social authentications. Hosting  − The applications can be deployed over secured connection to Firebase servers. .  Firebase is provided by Google so it is pretty much easier to use.As Firebase is a mobile platform it will you to develop apps very quickly. Lets get Started Search  Firebase  in your browser. Then you will get to many about firebase. Click  Go to Console  which in the top right. Now create a project in android studio. Visit  here  to get to know how to create an android project. You have to create a firebase project with same name of your android project. Click Add Project in the firebase view. For the Project Name give the same Na

Introduction to body-parser in Node.js

Image
What is body-parser? body-parser is the  Node.js body parsing middleware.  Middleware are the functions that have access to the  request object (req) , the  response object (res) , and the next middleware function in the application’s request-response cycle.In Node body-parser   is used to parse the body of requests. This provides the following parsers, JSON body parser Raw body parser Text body parser URL-encoded form body parser body-parser does not handle multipart bodies. For this you will have to use some other like, busboy  and  connect-busboy multiparty  and  connect-multiparty formidable multer Installation You can install body-parser by using the following code in your command line. npm install body-parser And then you have to require it in your app.js file Example: var bodyParser = require('body-parser'); //To parse URL encoded data app.use(bodyParser.urlencoded({ extended: false }))   //To parse json data app.use(bod

Creating a Schema in MongoDB

Image
What is a Schema ? Schema does not need to have the same set of fields or structure, and common fields in a collection’s documents. If you are familiar with sql queries, you might know that we define the variables  and data types in a predefined structure when creating tables.But when using schema you can consider the following points. Design your schema according to user requirements. Combine objects into one document if you will use them together. Otherwise separate them (but make sure there should not be need of joins). Duplicate the data (but limited) because disk space is cheap as compare to compute time. Do joins while write, not on read. Optimize your schema for most frequent use cases. Do complex aggregation in the schema. Lets try out how to create a schema to get a better idea. First create a directory in your project folder to store these separately. Now create file to create the schema.Here we should require Mongoose. Go through the  article  to get a b

MongoDB Connections in MEAN Stack

Image
This article will  help you to get to know how to build up a database connection using mongodb. For this I am using  Mongoose  which is done by using object modelling. First install mongoose using your command line and save it in the package.json file. npm install mongoose --save Now you can see that the dependency has been created in package.json file.Now require this into app.js file.Now you can create the database connection.Here before creating the connection, you should have run the mongo server. For that move on to the location where you have installed mongodb. If you haven't installed MongoDB refer  this article Now move on to the bin folder and run the mongod server by typing mongod. as the output you can get the following. Here port 27017 means the default port for mongo. Creating the Connection To create the connection create a new folder in your project called config in order to  reduce the complexity of the project.Then cre

Introduction To MEAN Stack

Image
MEAN stack is a friendly full stack java script development framework. It basically consist of MongoDB,express,AngularJS and NodeJS. Also i t is a  free and open-source JavaScript software stack for building dynamic web sites and web applications Set Up The Environment To start implementing with Mean Stack, you should follow following requirements. 01. Should have installed Node.js Should install a version above 6.3 as we are using Angular 2. If you are not familiar with the installation, visit  Introduction To Node.js  to get to know how to install Node.js . 02. Angular Version 2 03. MongoDB Can install in any OS. Refer  this article  to get to know how to install Mongodb. 04. Install ExpressJS Refer  the article  to get to know about express and how to install it. Now you can start developing a project using MEAN stack.  

Installing MongoDB into Windows

Image
This article will help you to get to know the way of installing MongoDB in to Windows. Lets get started. Step 01 : Download  MongoDB  from the website Step 02: Install it by following the steps in the setup. Step 03 : Move on to the bin folder in  MongoDB folder Go through  C:\Program Files\MongoDB\Server\3.6\bin to get the bin file. This path may change with the version that you are using.The window will looks like below. Step 04: Install mongo and mongod applications init. Open the command line in the bin folder to install mongod There it shows  an error that a database is not found.Here you need to create folder called data in c:/ and inside it another folder called db to store any information stored in Mongo. Now again try the mongod command and see. You will get an output like this which means that mongo is waiting for connections. To install mongo as same we did above type mongo in the command line.Then type db and see whether you get the

Working with Buttons in Android Studio

Image
From the  previous article  we went through a basic introduction on Android Studio.This article help you to get to know about Buttons in android studio.Open up Android studio and start. Given below is the edited code of the text view that I have used. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="Hello World!" android:textSize="36sp" android:id="@+id/textView" /> Go to your palette in the project. Then drag and place the button where you need in the content. Then move onto your text view. There you can see that the code for the button has been activated. There is an ID given to the button to identify a particular component which is always unique. You can give name to the button in android.text. Now give a background color to the button. Method 1 : Using inbuilt colors android: ba

Working with ExpressJS Framework

Image
Express.js or Express is an web application framework built for Node.js which works as a Free and Open Source Software (FOSS).It is specially designed for building web Applications and API's.It includes a lot of plugins,support and documentation which aids in developement. This article will help you to get a fresh start to work with Express.js.To start we should install Express in our working project. Go to your working project and open command line init. Then type the following code. npm install express --save Here we have used --save in the command to show the dependency installed in package.json file which shows all the packages that have installed in your project. After you have successfully installed express you can see a folder named node modules in your project where you can see the express folder . To check whether its working I have written a small code. var express =require('express'); var app =express(); //firing the function cons

Getting Started with Android Studio

Image
Hey all! If you are familiar with my articles, until now I have posted articles on PHP, CodeIgniter, Node.js and Angular.js . For a change I decided to give a fresh start on Android Studio as well. So lets get started. Hope you have installed Android Studio in to your computer. To start Android app development, go to your Android Studio and start a new project. Give a suitable name and location to your project. Select API 17 from the Minimum SDK in the window which you get next. Then click next and you will get a window of various interface designs. As we are creating a basic application I choose Empty activity as my template.Then click Finish.Then a Project  will be created . This may take couple of minitues based on the PC you are using. Click the project tab which I have highlighted in the left corner to get the whole project. Then go through each and every component in it. Go to app>src>main>res>layout>activity_main.xml to get the worki

How to serve a HTML page in Node.js

Image
Previous article  showed you how to create a basic server. Now lets look around the way to serve a html page using Node.js. First create a index.html file in your project folder. <html> <head>   <title>Home Page</title> </head> <body>   <h1>My first Template</h1>   <p>Hypertext Markup Language is the standard markup language for creating web pages and web applications. With Cascading Style Sheets and JavaScript, it forms a triad of cornerstone technologies for the World Wide Web</p> </body> </html> Now lets see how to serve this page. Take a look at the code below. var http=require('http'); var fs = require('fs'); var server = http.createServer(function(req,res){   console.log('request made :'+req.url);   res.writeHead(200,{'Content-Type': 'text/html'});   var read=fs.createReadStream(__dirname + '/index.html','utf8');   read

Creating a Server in Node.js

Image
From the previous article we got to know how to read and write files in Node.js. This article will help you to get to know about Clients and servers in Node.js First lets look at  what client and server really means. When we browsing internet by using chrome or any other browser we request for some data. This is where the client send its request to get a response particular to the clients request. Then the server acts on the request of the client and send a response which we finally see as our search results. Basically considering the client ad server each computer can be uniquely identified by using their IP addresses.So when communicating they need to get connected through the IP addresses.So the information is shared using different protocols like http. This transferring data is called TCP where the data is transmitted through data packets from server to client.  Using Node.js, we can use the same functionality to communicate with computers. Creating a Basic Server T

Read and Write files in Node.js

Image
Hey all...! This article will help you to know how to read and write files in Node.js. For this first of all we will create a small text file called hello.txt in our project folder and add a text in to it. For reading and writing modules we want to load one of the core modules which is known as fs in node modules. Lets require it in our working file as we did in previous articles. var fs = require('fs'); Then you have to read the file by using the following code. var readme=fs.readFileSync('hello.txt','utf8'); //blocking the code until we completing reading the filename console.log(readme); In the above code readFileSync is the method that we use to read a file.As you can see inside the parameters I have written the file name and utf8. as the file is read in binary that means using 1s and 0s to convert it we  use utf8. When you run the command line, you can read the hello.txt file. To avoid blocking the code below the reading code we can c

Modules in Node.js

Image
Node.js modules are set of functions that are used to include in your application.It is very similar to the libraries in javascript. When involving in development, we can either use built in modules or else we can create our own modules. Usually Modules are not designed in the same file that we are developing in. Modules are created and stored in separate files for the easy use. So lets create a separate file to create a module.I have created a file called module.js for further proceedings Now I am going to create a basic module to count the number of elements in an  array in my new file. var value =function(array){   return array.length + ' elements are there'; }; console.log(value(['A','B','C','D'])); Now run the command line and check the output Now we have created our module in an separate file.Now we should make this function available outside the module.js file.For that type the following code in module.js file. modu

The Global Object in Node.js

Image
In this article you will get to know about the Global Object in Node.js These Global Objects can be seen in modules that are their in Node.js. The Global object in Node can be considered as an object called Global.If youa are familiar with my previous articles on introduction, you may have already created our first command using Node (Click here  to get the article). Move on to the same file and open your command line. Before starting move on to the  Node.js Documentation  to get familiar with Global objects. Here you can see the documentation has given set of Global objects,Among them setInterval,setTimeout can be considered as window objects as well . lets try an example.Here I will write an function to setTimeout function setTimeout(function(){   console.log('You are after 5 seconds'); },5000); In this function you will get an timeout of  5 seconds which will be shown in the time out of 5000 milliseconds. When you run this in the terminal you will ge