Magistrate Postgres Stats for Developers

Express.js

Install the Plugin #

npm install YOUR_MAGISTRATE_URL

Add the Plugin to Your App #

const express = require('express');
const magistrate = require('magistrate/express');

const app = express();

app.use(
'/magistrate',
magistrate({
credentials: {
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'postgres',
database: 'sample',
},
// credentials: {
// connectionString: process.env.DATABASE_URL
// },
provider: 'rds',
authentication: (req, res, next) => next(),
debug: true,
})
);

app.listen(3000, () => {
console.log('Example app listening on port 3000!');
});

Options #

OptionTypeDefaultDescription
credentialsObjectnullAn object with a connectionString property or individual connection properties.
providerString''The database provider. One of: 'rds', 'heroku', or 'gcloud'
authenticationFunctionnullAn Express.js middleware function.
debugBooleanfalseLogs debug information to the stdout/stderr.