My application uses node.js and socket.io for communication between server and client. For communication between server and local hardware/programs I need a way to pass events and variables from node.js to python. The solution I am using is to store the values in Redis and access them from both node.js and python. First Redis needs to be installed; on Ubuntu simply run
sudo apt-get install redis-servernpm install hiredis redisFrom the node.js program Redis is used similar to other database clients.
var redis = require('redis')
,redisClient = redis.createClient();redisClient.set("keyName", "Value", callbackFunction);
redisClient.get("keyName", function (err, reply) {
console.log(reply.toString()); // prints "Value" to the console
});On the python side I install redis-py
sudo pip install redisimport redis;
r = redis.StrictRedis(host='localhost', port=6379, db=0);
y = r.get('keyName');
print y;