How to connect MySql database with Nodejs

Nodejs is a powerful platform which used for real-time data with flexible of handling data in file system or database side.  Today tutorial we are going to discuss about the connecting MySql with Nodejs.

Before getting into our code part, first will discuss about things needed for MySql connecting with Nodejs then will move to our code side.

First we need to check the MySql package is installed in our current Nodejs version or not. We have the command to check list or individual package installed in Nodejs. If the package is installed it will display the package else show “(empty)” value.

Display list of packages

Nodejs npm list command

Nodejs npm list command

Nodejs npm list packages

Nodejs npm list packages

Let’s see how to execute individual package and their output display. Continue reading

How to monitor connected and disconnect user IP Address in Nodejs

Nodejs have the ability to track the connected and disconnected user IP Address with socket.io node package.

What is Socket.io ?

Socket.io enables real-time directions which is event based communication. Its works on all the platform, browser or device on reliability and speed. We need to check few package it’s installed or not.  if not you can install socket.io and ip both package from your terminal.

Installing socket.io package

Installing socket.io package

Installing ip package

Installing ip package

Once you have installed both the packages, let’s include our needed package into our code and create server where our code will on that port.

var app = require('http').createServer(handler),
	io = require('socket.io').listen(app),
	ip = require('ip');
	app.listen(8001);

handler function will print “Welcome” in browser. Continue reading

How to track impression using image tag

Tracking the impression using image tag it’s playing important role, whenever you are sending email or include the image tag into another website to display your ads. It will send the parameters and get back the logs.

How Impression tracker works
Impression tracker display the image using server-side file and send back user details to server. It’s used to track your ads which display in different websites.

Impression tracker using image tag - codeasearch.com

Impression tracker using image tag – codeasearch.com

Let’s create simple image.html which have image tag and include image.php to display and capture logs entry.  Continue reading

Caching the Data using APC – Alternative PHP Cache

Now a days most of the website are used to cache their data to reduce the server load, Also speed up the response. We are going to discuss about the APC – Alternative PHP Cache.

APC is a Alternative PHP Cache as I already mentioned, its used to cache the data, remove and expire in the given time.  To work with APC first we need to enable php_apc.dll in windows and php_apc.so in Linux operating system.

Where to use APC ?

Consider you have a website with lots of content driven from database with data for all the users, on that time you cannot query the database each and every time. To avoid this case we will cache the data and share between the users. This will allow one time query and share the same data between the users.

Let’s see about fews function in APC.

apc_add – function used to store a data in key format and expire it in given TTL.

apc_add ( array $values [, mixed $unused = NULL [, int $ttl = 0 ]] )

Assigning value into $myData variable

<?php
    $myData = 'Welcome to APC';
    apc_add('myData',$myData);

apc_fetch – function used to fetch data from the given key. Continue reading

Persistent and Non-Persistent Cookie

Cookie used to store user data in form of text file or memory and access the values from it, Cookie are the part of HTTP header.

What is Persistent Cookie ?

Persistent Cookie which will store the data in text file with expire date and time. If you are access the website or particular page cookie will be created based on cookie name.  Next time If you are visiting the website or page it will be accessible from the cookie file which was created in the client browser.

Also Persistent Cookie is unsafe, because it will be easy viewable in the browser.

persistent_cookie.php

<?php
// creating the name:cookie_name_persistent and value:my cookie value with expire 1 hour
setcookie("cookie_name_persistent","my cookie value",time()+3600);

Above PHP file will create cookie and expire within 1 hour, you can view the cookie expire time in browser cookie part. Continue reading