I have two questions to ask you.
First, I'm using Codeigniter as my main framework development tool and I was wondering if it was a great idea to implement NodeJS inside it. I need to create a notifications center to send notifications to users.
Second, I implemented NodeJS inside Codeigniter but the problem is that, when I'm using the module "NowJS" with the server on, my page is loading but is never loaded. It's like if I was doing a super loop that doesn't stop.
Here is my server.js:
var mysql = require('mysql'),
//Client = require('mysql').Client,
connection = mysql.createConnection({
//Set user, and password for database
host: 'localhost',
user: 'root',
password: 'root',
database: 'db'
}),
exec = require('child_process').exec,
server = require('http').createServer().listen(8000),
nowjs = require("now"),
everyone = nowjs.initialize(server);
connection.connect(function(err) {
// connected! (unless `err` is set)
console.log( err );
console.log('connection to database established');
});
everyone.now.distributeMessage = function(message,session_cookie) {
//Call the script that decrypts the session id
//NOTE:the path to index.php must be relative to this script
exec('php index.php user_session decrypt ' + encodeURIComponent(session_cookie), function (error, stdout, stderr) {
var parts = stdout.split(';');
var session_id = parts[1].split(':')[2];
var ip_address = parts[3].split(':')[2];
var query = 'select user_data from ci_sessions where session_id=' + session_id +
' and ip_address=' + ip_address;
client.query(query, function (err, results, fields) {
if (results) {
//If anything is returned log the userdata and call the clientside function
console.log(results[0].user_data);
everyone.now.receiveMessage(message);
}
});
});
};
Here is my client.js
now.ready(function(){
// "Hello World!" will print on server
now.logStuff("Hello World!");
});
And this is my markup for the HTML
<script src="http://localhost:8000/nodejs/nowjs/now.js"></script>
<script src="/script/client.js"></script>
Also, can i use socket.io for this notifications system ?
Thanks in advance
Simon