Connecting via Node.js

First, install node-postgres for your node project.

npm install pg

Then sign in to bit.io and click "Connect" to get your connection info.

14701470

Using that information, you can connect to bit.io and query either yours or anyone else's public repo. Try copying the code below and swapping out the connection information.

const { Client } = require('pg');

// Create a client using the connection information provided on bit.io.
const client = new Client({
    user: 'adam_demo_db_connection',
    host: 'db.bit.io',
    database: 'bitdotio',
    password: 'C1GL_Z9Qthisisfake6XghrkhcW',
    port: 5432,
});
client.connect();

client.query('SELECT * FROM "terrybit/real-estate"."real_estate";', (err, res) => {
    console.table(res.rows); // you could also just console.log, but console.table is neat :)
});

Now run the program using node and you should see the rows you requested printed out in the console.

node main.js
19971997

Did this page help you?