No output from pg-monitor
No output from pg-monitor
I initialize and use massive-js in Koa v2 like this:
// ./app.mjs
import Koa from 'koa';
import massive from 'massive';
import monitor from 'pg-monitor';
import promise from 'bluebird';
// ...
const app = new Koa();
// ...
const db = massive({
host: process.env.PGHOST || 'localhost',
port: process.env.PGPORT || 5432,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
}, {
scripts: './db',
}, {
promiseLib: promise,
});
app.context.db = db;
monitor.attach({ options: db.driverConfig });
info(`monitor.isAttached(): ${monitor.isAttached()}`); // Returns: true
// ./routes/index.mjs
router.get('/massive', async (ctx, next) => {
const db = await ctx.db;
ctx.body = {
tables: await db.listTables(),
views: await db.listViews(),
};
});
But pg-monitor's output remains silent:
[nodemon] starting `node --experimental-json-modules ./bin/www.mjs`
(node:18416) ExperimentalWarning: The ESM module loader is experimental.
app:info monitor.isAttached(): true +0ms
app:info Listening on port 3001 +3ms
app:info ::ffff:127.0.0.1 - GET /massive HTTP/1.1 200 154 - 4.300 ms +3s
app:info ::ffff:127.0.0.1 - GET /massive HTTP/1.1 200 154 - 0.881 ms +447ms
I initialize massive-js this way, because the official Koa example in the docs giving me SyntaxError:
app.context.db = await massive({
host: '127.0.0.1',
port: 5432,
database: 'appdb',
user: 'appuser',
password: 'apppwd'
});
Generates the following error:
file:///.../app.mjs:51
app.context.db = await massive({
^^^^^
SyntaxError: Unexpected reserved word
I think because using await
outside async
functions is not allowed. The minimal Koa example in the docs also giving me the same error in Node v13.10.0.
I want some examples how to initialize properly pg-monitor with massive globally for all routes. Thank You for the help!
Edited by István Lantos