Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Last active September 1, 2015 02:15
Show Gist options
  • Save lvidarte/a173ff8ef95b6c1c686b to your computer and use it in GitHub Desktop.
Save lvidarte/a173ff8ef95b6c1c686b to your computer and use it in GitHub Desktop.
Simple nodejs server with redis connection
var http = require('http');
var redis = require('redis');
var client = redis.createClient(6379, 'app_db');
http.createServer(function (req, res) {
client.incr('counter', function (err, reply) {
console.log('Counter value', reply);
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({ counter: reply }) + "\n");
});
}).listen(3000, '0.0.0.0');
console.log('Server running at http://0.0.0.0:3000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment