const Pool = require('pg').Pool
const pool = new Pool({
user: 'postgres',
host: '<ip-address>',
database: 'cexplorer',
password: '<password>',
port: 5432,
})
const getMetadata = async (callback) => {
await pool.query('SELECT * FROM meta', callback)
};
app.get('/metadata', function (req, res) {
getMetadata((error, result) => {
if (error) {
throw error;
}
res.send(result);
})
});
const requestOptions = {
method: 'GET',
headers: {'Content-Type': 'application/json'}
};
fetch('http://localhost/metadata', requestOptions)
.then(response => response.text())
.then(data =>
this.setState({
metadata: JSON.parse(data)
}, () => {
console.log(this.state.metadata);
})
);