Skip to content

Instantly share code, notes, and snippets.

@jqtrde
Created November 26, 2013 22:45
Show Gist options
  • Save jqtrde/7667686 to your computer and use it in GitHub Desktop.
Save jqtrde/7667686 to your computer and use it in GitHub Desktop.
Simple example on using CartoDB.js with Express.
// 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