Skip to main content

NodeJs and Mongo DB

Creator of node js

Ryan Dahl invented in 2009 (Node.js was invented in 2009 by Ryan Dahl and other developers working at Joyent. Node.js was created and first published for Linux use in 2009. Its development and maintenance was led by Dahl and sponsored by Joyent, the firm where Dahl worked.). This is a framework

=========================================================================

 Describe NodeJs 

- Node.js - is an open source, cross-platform runtime environment for server-side and networking application.

- Node.js applications are written in Javascript, and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop and IBM.


- Node.js open all available ports around 65534 using single process.

- Node.js loads app in memory and sets as serve wait http comes through.


 - This is based on Google's V8 Javascript Engine. (Google's V8 javascript engine compiles javascript into machine and assembly code. sizable improvement in running the js. compiles javascript into machine level code.)

What is Node.js?
Its Single Threaded.
No worries about: race conditions, deadlocks and other problems that go with multi-threading.
Almost no function in Node directly performs I/O, so the process never blocks. Because nothing blocks, less-than-expert programmers are able to develop scalable systems.


Can node replace any java, hybernate, spring?
- yes we can, Node is backed server framework which can do in java. 

Node.js VS Angular Js

Node.js is server side application. allows you to create server side javascript application. server side sockets.
Design for single threaded  is due to CPU intensive task. we try not to do CPU intensive tasks, web workers kind of tasks.
Rendering front-end , getting out templates are handle in nodejs. Resize/edcode of image is not we suited in Nodejs unless you use webworkers etc.
In Node.js serve multiple request do not have over head of switching threads and do not have overhead to context switching.

Angular js is only at front end there is some amount of overlap. used to create single page application, making calls from your browsers side. you cannot use the angular js  can not used to create REST backend.


Use cases of Node.js

Walmart - server side web application
linkedin - Highly scalable.
Voxer - Low memory consumption.


Node.js is an open-source, cross-platform runtime environment for developing server-side web applications. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, Linux, FreeBSD, NonStop,[3] IBM AIX, IBM System z and IBM i. Its work is hosted and supported by the Node.js Foundation,[4] a collaborative project at Linux Foundation.

Node.js provides an event-driven architecture and a non-blocking I/O API designed to optimize an application's throughput and scalability for real-time web applications. It uses Google V8 JavaScript engine to execute code, and a large percentage of the basic modules are written in JavaScript. Node.js contains a built-in library to allow applications to act as a web server without software such as Apache HTTP Server, Nginx or IIS.

=========================================================================

NodeJs is set of libraries on top of v8.

Real time web node.
Allows you to build scalable network applications using JavaScript on the server side.
v8 javscript Runtime (Engine) (virtual engine)- v8 javascript engine inside of chrome. same as used in chrome browser at run time. Node js is wrapper along with v8 engine.

=========================================================================

We can build using nodejs

web socket server - use for chatting etc. lots of browsers connect to server and messaging going on to do this socket should be open.
we can build our own Tcp server.
Fast file upload client - file uploading fast in a peaces.
Ad server - to server the advertisements to other servers.
Any Real time Data Apps - 

=========================================================================

What is nodejs not?

Not a web server - we can build web server on top of nodejs but nodejs is not web server.
Not for begginers - its very low level.
Not multi-treaded application. its single threaded server.

=========================================================================

Objective: print file contents

- Blocking code
--
    Read the file from filesystem, set equal to "contents"
    print contents
    Do something else

- Non-Blocking code
--
    Read file from filesystem
    when ever you're complete, print the contents
    Do something else.

=========================================================================

Blocking vs Non-Blocking

- Blocking code - stop process until complete
 var contents = fs.readFileSync("/etc/hosts");
console.log(contents);
console.log("Do something else.");

- Non-Blocking code - contineous process with process to execution in callback function - This is best way on top of blocking
fs.readFile("/etc/hosts", function(err, contents){
console.log(contents);
});
console.log("Do something else.");
OR
var callback = function(err, contents){
console.log(contents);
}
fs.readFile("/etc/hosts", callback);

=========================================================================

Why javascript for nodejs ?

JavaScript has certain characteristics that makes it very different than other  dynamic languages, namely that  it has no concept of threads. Its model of concurrency is completely based around events.


  The Node.js JavaScript runtime and associated ecosystem, including the npm package manager.

=========================================================================

Installation steps for nodejs and express

//for fedora the following are installation steps,

//install node.js
$ sudo yum install nodejs npm

//Then to test node run simple javascript
$ echo 'console.log("Hello World");' > /tmp/hello.js
$ node /tmp/hello.js

//out put
Hello World

//Then install express framework for developing web app
$ sudo npm install express -g

$ sudo npm install -g express-generator //-g globally

$ express nodejsapp


//install dependencies:
$ cd nodejsapp
$ npm install

//run the app:
$ DEBUG=nodejsapp:* npm start

OR

//simple run your project
$ npm start

//Then check by running url in browser
http://localhost:3000



Server Side - Node.Js
ClientSide - Jquery, HTML, CSS
View Parser Engine - Jade
Development framework - Express Framework
=========================================================================

Some more concepts about NodeJs

 - Node js is way to develop server side application. website, chat program, game, social network, server side application,  to connect people.
 

- Node js is useful for awesome for real time stuff if you make chat app update in real time.
php in not great for real time app as chat application because it very heavy, slow uses lots of memory etc, uses lots of memory resources.

Concepts in NodeJs

- When ever you make objects in node it is just similar like creating object in javascript.
 example:
var person = {
    firstName: "Nilesh",
    lastName: "Pangul",
    age: 31
};
console.log(person);

- Any function without any return will treat as undefined.

- In nodejs we can use Anonymus function and assign the function to some variable for future use. The variable then we can use in another function as reference parameter and use same.
example:
var printSomething = function() {
    console.log('I am printing something!!!');
};

//call function like
printSomething();

//the above variable we can call in another function like
setTimeout(printSomething, 3000);

* Handling Multiple Requests in NodeJs

Functions pass them as parameters to other functions with callback and vice versa.
example:
customers >>> Server >>> DB shef

function placeOrder(orderNumber){
    console.log('Customer order: ', orderNumber);

    cookAndDeveliverFood(function(){
        console.log('Deliver food order: ', orderNumber);
    });
}

//simulate a 5 second operation
function cookAndDeliverFood(callback){
    setTimeout(callback, 5000);
}

//simulate users web request
placeOrder(1);
placeOrder(2);
placeOrder(3);
placeOrder(4);
placeOrder(5);

//Out put:
Customer order: 1
Customer order: 2
Customer order: 3
Customer order: 4
Customer order: 5
Deliver food order: 1
Deliver food order: 2
Deliver food order: 3
Deliver food order: 4
Deliver food order: 5

* Understanding References to Objects

- When ever work with node everything is reference.
example:
var personObject = {
    firstName: "Nilesh",
    lastName: "Pangul",
    age: 31
};
console.log(person);

var Person = personObject;
Person.firstName = "Kamlesh";

console.log(personObject.firstName);

//Out put
Kamlesh



* "this" keyword

- it just refers to a thing that call it. Reference to what ever is calling him.
example:
var personObject = {
    firstName: function(){
        console.log('My first name is Nilesh');
        console.log(this===personObject); //true
    }
};

personObject.firstName();

//Out put
My first name is Nilesh
true

- In NodeJs The default calling context is global

example:
function doSomethingWordthless(){
    console.log('I am worthless');
    console.log(this===global); //true
}

//Out put
I am worthless
true


* Prototyping in NodeJs

- Prototyping is ability do add additional messages/method/functions or properties to objects and classes.

Example: Create Game which has many users which can have different play actions


function User(){
    this.name = "";
    this.life = 100;
    this.giveLife = function giveLife(targetPlayer){
        targetPlayer.life += 1;
        console.log(this.name + 'gave 1 life to' + targetPlayer.name);
    }
}

//Create users
var Nilesh = new User();
var Kamlesh = new User();

//Assign name to user
Nilesh.name = "Nilesh";
Kamlesh.name = "Kamlesh";

//Give life to other user
Nilesh.giveLife(Kamlesh);
console.log("Nilesh : "+ Nilesh.life);  //out put 100
console.log("Kamlesh : "+ Kamlesh.life); //out put 101

//You can add extra function to all object using prototype
User.prototype.uppercut = function uppercut(targetPlayer){
    targetPlayer.life  -= 3;
    console.log(this.name + ' just uppercut ' + targetPlayer.name);
}

//call uppercut function
Kamlesh.uppercut(Nilesh);
console.log("Nilesh : "+ Nilesh.life);  //out put 97
console.log("Kamlesh : "+ Kamlesh.life); //out put 101

//You can add properties to all objects using prototype
User.prototype.magic = 60;

console.log(Nilesh.magic); //out put 60
console.log(Kamlesh.magic); //out put 60

===================================================

* Modules in NodeJs

In nodejs instead of writing code in one file devide code in to files and link call where ever use want to use is called modules.

Example: Create module in NodeJs


//create main file app.js and another file movies.js

//movies.js code

function printAvatar(){
    console.log('Avatar number : AV-1');
}

function printRecord(){
    console.log('Record number : 1');
}

module.exports.avatar = printAvatar; //define sharable functions to module

//app.js code
var movies = require('./movies'); //file name without extension .js
movies.avatar(); //out put Avatar number : AV-1




Example: Define and call module in different way

//movies.js code
module.export = [
    printAvatar = function (){
        console.log('This is avatar');
    },
   
    printChapter = function (){
        console.log('This is chapter');
    },

    favMovie = 'Vivah'; // define variable
];

//app.js code
var movies = require('./movies');

movies.printAvatar(); // out put This is avatar

movies.favMovie; // out put Vivah
 




* Shared State of Modules

Any time you export object from module that object share among every other module

Example: Share the movies module to other different modules

//movies.js code 
module.export = [ 
    favMovie = ''
];

//nilesh.js code
var movies = require('./movies');
movies.favMovie = 'The Notebook';
console.log('Nilesh favorite movie is : ' + movies.favMovie); //out put The Notebook

//kamlesh.js code

var movies = require('./movies');
console.log('Kamlesh favorite movie is : ' + movies.favMovie); //out put The Notebook

//app.js code
require('./nilesh');
require('./kamlesh');

//Out put
Nilesh favorite movie is : The Notebook
Kamlesh favorite movie is : The Notebook //if property is modified by another object then latest modified value will be refer throughout





* Object Factory

Any time you export object then it should give you the default of that object (means return new object every time).

Example: Create the movies module and user to other different modules as fresh object

//movies.js code
module.export = function (){
    return [     
         favMovie = ''
    ]
}

//nilesh.js code
var movies = require('./movies');
var nileshMovie = movies();
nileshMovie.favMovie = 'The Notebook';
console.log('Nilesh favorite movie is : ' + movies.favMovie); //out put The Notebook


//kamlesh.js code
var movies = require('./movies');
var kamleshMovie = movies();
kamleshMovie.favMovie = 'The real Hunter';
console.log('Kamlesh favorite movie is : ' + movies.favMovie); //out put The real Hunter


//app.js code
require('./nilesh');
require('./kamlesh');


//Out put
Nilesh favorite movie is : The Notebook
Kamlesh favorite movie is : The real Hunter


===================================================

* Core Modules in NodeJs

When ever you using the core module do not use the path in require. It is common practice to give name of object and module same.

Example: Core module 'fs' file system to create, edit, write, delete files

* 'fs' core module


//app.js code
var fs = require('fs');

//create file and write into file
fs.writeFileSync('corn.txt', 'Corn is very good for health.'); //this creates file in same directory level and writes data

//read file content
console.log(fs.readFileSync('corn.txt')).toString(); //out put Corn is very good for health.


* 'path' core module

used when we use file path, path module is used to normalize the file path depends upon OS.

Example: use of path core module
var path = require('path');

var websiteHome = 'Desktop/Nilesh/theme//index.html';
var websiteAbout = 'Desktop/Nilesh/theme/about.html';

console.log(path.normalize(websiteHome)); //Desktop/Nilesh/theme/index.html
console.log(path.dirname(websiteAbout));  //Desktop/Nilesh/theme
console.log(path.basename(websiteAbout)); //about.html
console.log(path.extname(websiteAbout));  //.html
===================================================

* Creating a Basic Server

Nodejs is different from plain javascript, plain javascript is made for web browser. nodjs is responsible for server site connections like connect server, request data, send data to server etc.

* Create http server


//server.js
var http = require('http');

http.createServer(onRequest).listen(8888);
console.log('Server is running...');

function onRequest(request, response){
    console.log('A user made request ' + request.url);
    response.writeHead(200, {'Content-Type' : 'text/plain'});
    response.write('Here is some data from server.');
    response.end();
}

//first run the server.js and then run the http://localhost:8888 url in browser

//browser out put
Here is some data from server.

//console out put
Server is running...
A user made request/
A user made request/favicon.ico

* Simple Web File Server


Example: Render the file as out put to response

//index.html code
<html>
<head><title>This is web site</title><head>
<body>
Wow I am connected to the web page.
</body>
</html>

//server.js code
var http = require('http');
var fs = require('fs');

http.createServer(onRequest).listen(8888);

console.log('Server is running...');

//handle a user request
function onRequest(request, response){

    if(request.method == 'GET' && request.url == '/'){

        response.writeHead(200, {'Content-Type' : 'text/plain'});
        fs.createReadStream('./index.html').pipe(response);

    }else{
        send404Response();
    }
}

function send404Response(response){
    response.writeHead(404, {'Content-Type' : 'text/plain'});
    response.write('Error: Page not found.');
    response.end();
}

//first run the server.js and then run the http://localhost:8888 url in browser

//browser out put
Wow I am connected to the web page.

//console out put
Server is running...
===================================================

* Connect module/package in NodeJs 

(install this module and then use)

connect module is used to connect and handle the request for different purposes like authenticate, process request etc.

Example: 

var connect = require('connect');
var fs = require('fs');

var app = connect();

function doFirst(request, response, next){
    console.log('Nilesh');
    next();
}

function doSecond(request, response, next){
    console.log('Kamlesh');
    next();
}

app.use(doFirst); //run this method and then proceed to next
app.use(doSecond);

http.createServer(app).listen(8888);
console.log('Server is running...');



Example: (Call connection to connect different pages from server)

var connect = require('connect');
var fs = require('fs');

var app = connect();

function profile(request, response)
{    console.log('User requested profile');
}

function forum(request, response){   
 console.log('User requested forum');
}

app.use('/profile', profile); //call profile function on request for profile url

app.use('/forum', forum); //call forum function on request for forum url


http.createServer(app).listen(8888);

console.log('Server is running...'); 



===================================================

Express (web framework for node)

- Popular web framework for node, entire setup for folder. file structure etc gives express for development in node.

Express JS - Wen framework for Node.js. It is an npm package.

Basics of Node.js: npm
npm - used to stand for Node Package Manager. npm is not Node.js specific tool
npm is registry of reusable modules and packages written by various developers. Even you can publish you npm packages.
There are two ways to install npm packages-
1. locally - To use and depend on the package from your own module or project.
2. Globally - To use across the system, like a command line tool.

 

Express JS also provides tool to create a simple folder structure for your app.

- express newapp will create a project called newapp in the current working directory along with a simple folder structure.
- the dependecies will the be installed by doing a cd newapp and then npm install
- to tun the app
- node app //this is where the server is run and listing on a port.



Folder structure of express-
projectdir
- idea - core files
- bin
-- www - starting point/startup script of the project
- node_modules - all modules in addition to core modules
- public - images, javascript, styles
- routes
-- index.js
-- users.js
- views - html code view files
- app.js - core foundation of project


installation 
node -v
npm -v (install dependency)
npm install -g express  //in the main project folder
npm install -g express-generator //-g globally
express appname  //create application
npm install   //install dependency mentioned in package.json
npm install -g nodemon   //monitors changes in application nodemon bin/www


 

Template/view engine used like,
jade
HJS - hogen js template  (to install: express appname --hogen -c less)
EJS -

EJS
in Express framework when we choose the template engine EJS then every file in views folder has .ejs extension. The files in views contains html code. Just like php if we want to use some dynamic variables passed from routes file then we can use syntax. <% %> to fetch and display the variables in .ejs files.

To include anothe .ejs in .ejs file use syntax,
<% include template/header.ejs %>

//global variable in express

Any time if you need some variable which we need throughout the site then use app.locals.variablname
Example:

//app.js code
var express = require('express');
var app = express();
app.locals.points = "123"; //points variable we can use throughout

//index.ejs
<%= points %>

Example: use json file data


//app.js code
var express = require('express');
var app = express();
app.locals.videosjson = require('./videos.json'); //points variable we can use throughout

//index.ejs
<%= videosjson.categoryname %>

//looping through json data
<ul>
<% videosjson.categories.forEach(function(item){ %>
    <li> <%= item.videoname %></li>
<% }); %>
</ul>


=========================================================================

NODEJS - Hello World code . hello.js

var http = require("http"); //how we require modules

http.createServer(function(request, response){

response.writeHead(200); // status code in header

response.write("Hello World"); //response body

response.end(); //colse the connection

}).listen(8080);//listens for connections for this port

consolde.log("listing on port 8080...");

Known Events --- Request >>> connection >> Close. contineous 


=========================================================================

example: Hello World Code in php and node js

<?php

//hello.php blocking type of execution of code, Like fetch url from website and wait for 2 sec to come back

echo "Hello";
sleep(2);
echo "World";
 ?>

//hello.js continuous execution of code, Code does not spinning in busy loop CPU goes to zero and does other stuff and come back to code execution after set time out it does not sleep
setTimeout(function(){
console.log("World");
}, 2000);
console.log("Hello");

=========================================================================

example: create web server using node js


//web-server.js
var http = require("http");

var server = http.createServer(function(req, res){

    res.writeHead(200, { 'conten-type' : 'text/plain' });

    res.end("Hello World \n");
});

server.listen(8000);

//run the url in browser http://localhost:8000 it will print Hello World. You can also check the by running url in command line

=========================================================================

example: create tcp server using nodejs


//tcp-server.js

var net = require("net");

var server = net.createServer(function(socket){
    socket.write("Hello \n");
    socket.end("World \n");
});
server.listen(8000);

//to run above code write in command line bellow,
//need to start server and run page like
$ node tcp-server.js

//run bellow code in another command line tab
$ telnet localhost 8000

OR use net caf
$ nc  localhost 8000

=========================================================================

Example: create chat server using nodejs


//chat-server.js

var net = require("net");

var sockets = [];

var server = net.createServer(function(socket){
    sockets.push(socket);

    socket.on('data', function(d){
        for(var i=0; i < socket.length; i++){
            if(sockets[i]==socket) continue;
            sockets[i].write(d);
        }
    });

    socket.on('end', function(){
        var i = sockets.indexOf(socket);
        sockets.splice(i, 1);
    });

});
server.listen(8000);

//run bellow code in another command line tab
$ telnet localhost 8000

=========================================================================

mongodb installation

//Installation steps for mongodn in fedora 20

$ sudo vim /etc/yum.repos.d/mongodb.repo

//insert bellow code and save
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

//check for system updates
$ yum -y update

//install mondodb
$ yum -y install mongodb-org mongodb-org-server

//mondodo commands

//Start-Up MongoDB
$ systemctl start mongod

//Check MongoDB Service Status
$ systemctl status mongod

//Start the MongoDB Service at Boot
$ systemctl enable mongod

//Summary List of Status Statistics (Continuous)
$ mongostat

//Summary List of Status Statistics (5 Rows, Summarized Every 2 Seconds)
$ mongostat --rowcount 5 2

//Enter the MongoDB Command Line
$ mongo

//use different port for mongodb
mongo --port 22222

//Shutdown MongoDB
systemctl stop mongod

//MongoDB - Create Database
use DATABASE_NAME

//show all databases
show dbs



//mongodb related commands

//go to mongo command prompt
$ mongo


//list all the databases
>show dbs


//use or select database OR (MongoDB use DATABASE_NAME is used to create database. The command will create a new database, if it doesn't exist otherwise it will return the existing database.)
>use databasename


//to show current database using name
>db

//show all the tables/collections from the selected database
>show collections


//create collection/table in mongo db (db.createCollection(nameoptions))
>db.createCollection(<name>, { capped: <boolean>,
                              autoIndexId: <boolean>,
                              size: <number>,
                              max: <number>,
                              storageEngine: <document>,
                              validator: <document>,
                              validationLevel: <string>,
                              validationAction: <string>,
                              indexOptionDefaults: <document> } )
 
  

//show all the records from collection/table
>db.<collectionname>.find()



//count all the records from collection/table
>db.<collectionname>.find().count()

//sort ascending (1), descending (-1) order
>db.<collectionname>.find().sort({$natural:1});

>db.<collectionname>.find().sort({fieldname:1}); //1 = asc or -1 = desc

//fetch bunch of limited records with ascending sort
>db.<collectionname>.find().sort({_id:1}).limit(50); 


//get selected rows on conditionali basis
db.<collectionname>.find({first_name : "My Name"})

//to describe the collection in mongodb
db.hp_sessioninfo.findOne()

//remove row from database
db
.<collectionname>.remove( { first_name : "My Name" } )




Use mongodb in nodejs

$ mongod --dbpath /var/www/html/projectname/data

//go to command prompt of mongo
$ mongo 

//create database
$ use nodejsapp1dbname

//insert sample data in doejs
db.userlist.insert({'username' : 'test1','email' : 'test1@test.com','fullname' : 'Nilesh Pangul','age' : 27,'location' : 'Maharastra','gender' : 'Male'})
=========================================================================

popular framework for node js is "express js"

telnet
netcaf (nc)
npm - node package management
npm install socket.io

ab -n 100 -c 100 http://127.0.0.1:8000


JETBRAINS IDE  platform to develop the node js for windows- paid

Sublime text -text editor free for Mac OS.

========================================================================= 

References : -
https://nodejs.org
https://nodejs.org/api/documentation.html
https://www.youtube.com/watch?v=GJmFG4ffJZU
https://www.youtube.com/watch?v=eqlZD21DME0

https://www.youtube.com/watch?v=jiSFfpw3Btc&index=3&list=PL6gx4Cwl9DGBMdkKFn3HasZnnAqVjzHn_

==========================================================================

Node JS Interview Questions: 

  • what is node js?
  • explain the working of node js?
  • what is synchronous and asynchronous in nodejs?
  • example of synchronous and asynchronous function in nodejs?
  • how to find the version of node js?
  • what is a module in nodejs?
  • how to install modules in nodejs?
  • how to upgrade modules in nodejs?
  • how to delete a module in node js?
  • what is package.json?
  • what is the purpose of ~ and ^ sign in package.json?
  • Name some of the attributes of package.json?
  • How to uninstall a dependency using npm?
  • How to update a dependency using npm?
  • how to include a module or What is the command that is used in node.js to import external libraries?
  • What is Callback in node.js?
  • what is npm?
  • What is typically the first argument passed to a Node.js callback handler?
  • What is an error-first callback?
  • can node js support multiple thread?
  • will node js work if javascript is disabled?
  • Where to use node js (practical example)?
  • Where not to use node js?
  • differnce betweemn node js and ajax?
  • What is callback hell and how can it be avoided?
  • Which framework you have used for node js?
  • Testing tool used for nodejs?
  • error handling in node js
  • What is a blocking code?
  • How Node prevents blocking code?
  • What is Event Loop?
  • What is Event Emmitter?
  • What is purpose of Buffer class in Node?
  • What is Piping in Node?
  • Which module is used for file based operations?
  • Which module is used for buffer based operations?
  • Which module is used for web based operations?
  • fs module provides both synchronous as well as asynchronous methods.
  • What is difference between synchronous and asynchronous method of fs module?
  • Name some of the flags used in read/write operation on files.
  • What are streams?
  • How many types of streams are present in Node.
  • Name some of the events fired by streams.
  • What is Chaining in Node?
  • How will you open a file using Node?
  • How will you read a file using Node?
  • How will you write a file using Node?
  • How will you close a file using Node?
  • How will you get information about a file using Node?
  • How will you truncate a file using Node?
  • How will you delete a file using Node?
  • How will you create a directory?
  • How will you delete a directory?
  • How will you read a directory?
  • What is the advantage of using node.js?
  • Can you access DOM in node?
  • What are the pros and cons of Node.js?
  • What does it mean non-blocking in node.js?

Comments

Popular posts from this blog

Learn phpfox

PHPFox  is a social network script, it is an internet application and when you install it, it is a website. The  phpfox  script comes in 3 packages, each with a different set of modules. it has two products: 1. Nebula (upto phpfox 3.8) 2. Neutron (Newer) You can check the demo on :  http://www.phpfox.com =================================================== To clear cache in phpfox follow the following steps, admincp >> Tools >> Maintenance >> Cache Manager >> Click on Clear All button =================================================== To work facebook app on local Following settings need to done in facebook app   1) go => setting => Advance 2) see "OAuth Settings" area and set "Valid OAuth redirect URIs" =  http:// projectdomain /index.php?do=/user/login/, http:// projectdomain .com/index.php?do=/user/register/, http:// projectdomain .com, http:// projectdomain .com/index.php 3) en...

Interview PHP

>> Why do you want to work at our company? Sir, It is a great privilege for anyone to work in a reputed company like yours. When I read about your company I found that my skills are matching your requirements.  Where I can showcase my technical skills to contribute to the company growth. >> What are your strengths? I am very much hard working and optimistic. Hard Working: Work with dedication and determination. Optimistic: work with positive attitude. I am a team player. I am also very hardworking, and will do what it takes to get the job done. >> What are your weaknesses? Gets nervous when talk to strangers I am a bit lazy about which I am not interested I tend to trust people too easily. I am working on it. >> Why should I hire you? With reference to my work experience, I satisfy all the requirement for this job. I am sincere with my work and would never let you down in anyway. I promise you will never regret for the decision to a...

How to Make Your Own PHP Captcha Generator

In this article we will create file based simple yet successful captcha generator. 3 Major Anti-spamming techniques used? Mathematical Operation like Random number + Random Number = -> The user must specify the answer Random word -> User must type the word Random question -> Obvious one which the user should answer correctly [ex: Are you human?] How Captcha works? The captcha generator generates an IMAGE with the question and then put up a session variable storing the value. User input though an input box. Using php POST, we compare the session variable data with the user input and tell whether its a bot or human. Its coding time The Code First let's write the php script which generates the captcha image. We use the simple header-content change technique, from which we can easily bring up an image from a given text. captcha.php PHP Code: array("Num" => "Num"), 1 => array("Are y...