Created
November 26, 2013 22:45
-
-
Save jqtrde/7667686 to your computer and use it in GitHub Desktop.
Simple example on using CartoDB.js with Express.
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
// requirements | |
var carto = require('cartodb'), | |
express = require('express'), | |
secret = require('./secret.js'); | |
// initialize express | |
var app = express(); | |
// a friendly little route | |
app.get('/', function(req, res) { | |
// connect to carto | |
var client = new carto({ | |
user:secret.USER, | |
api_key:secret.API_KEY | |
}); | |
var outputRows = function(err, data) { | |
console.log(data.rows); | |
res.send(data.rows); | |
}; | |
// build your query | |
// replace YOURTABLE with, well, your table | |
client.on('connect', function() { | |
client | |
.query("select * from YOURTABLE limit 5", outputRows); | |
}); | |
client.connect(); | |
}); | |
// start listening | |
app.listen(3333); | |
console.log('Boom'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment