Last active
September 1, 2015 02:15
-
-
Save lvidarte/a173ff8ef95b6c1c686b to your computer and use it in GitHub Desktop.
Simple nodejs server with redis connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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