question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to append this plugin when using pm2

See original GitHub issue

How to append plugins is explained in two places:

Both do not explain how this would work if you are using something like pm2 to start the server which I guess almost everyone does in production.

I have tried a few solutions:

  1. using ecosystem.config.js:
module.exports = {
  apps: [{
    name: 'postgraphile',
    script: './node_modules/.bin/postgraphile',
    args: '-c postgres://user:password@localhost:5432/dbname --jwt-token-identifier auth.jwt_token --default-role postgres --jwt-secret secret -s dbname --cors --host 0.0.0.0 --append-plugins `pwd`/node_modules/postgraphile-plugin-connection-filter/index.js --disable-query-log',
    instances: 1,
    exec_mode: 'cluster',
  }],
}

then starting using it:

pm2 start ecosystem.config.js
  1. passing options inline:
pm2 start ./node_modules/.bin/postgraphile -- -c postgres://user:password@localhost:5432/dbname --append-plugins `pwd`/node_modules/postgraphile-plugin-connection-filter/index.js --jwt-token-identifier auth.jwt_token --default-role postgres --jwt-secret secret -s dbname --cors --disable-query-log

Both lead to this error:

1|postgrap | Failed to load plugin './node_modules/postgraphile-plugin-connection-filter/index.js'
1|postgrap | Error: Cannot find module './node_modules/postgraphile-plugin-connection-filter/index.js'
1|postgrap |     at Function.Module._resolveFilename (module.js:547:15)
1|postgrap |     at Function.Module._load (module.js:474:25)
1|postgrap |     at Module.require (module.js:596:17)
1|postgrap |     at require (internal/module.js:11:18)
1|postgrap |     at names.map.rawName (/home/alex/node_modules/postgraphile/build/postgraphile/cli.js:198:20)
1|postgrap |     at Array.map (<anonymous>)
1|postgrap |     at loadPlugins (/home/alex/node_modules/postgraphile/build/postgraphile/cli.js:190:18)
1|postgrap |     at Object.<anonymous> (/home/alex/node_modules/postgraphile/build/postgraphile/cli.js:262:20)
1|postgrap |     at Module._compile (module.js:652:30)
1|postgrap |     at Object.Module._extensions..js (module.js:663:10)

But it works if I use:

npx postgraphile \
  -c postgres://user:password@localhost:5432/dbname \
  --append-plugins `pwd`/node_modules/postgraphile-plugin-connection-filter/index.js  \
  --jwt-token-identifier auth.jwt_token \
  --default-role anon \
  --jwt-secret secret \
  -s dbname \
  --cors

So obviously ./node_modules/postgraphile-plugin-connection-filter/index.js exists.

The ecosystem.config approach works for me in a different project where I do not use this plugin.

So what could be wrong?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
benjiecommented, Jun 14, 2018

Ah; okay 👍 I’ve updated the docs anyway: http://graphile.org/postgraphile/extending/#loading-additional-plugins

0reactions
mattbretlcommented, Jan 10, 2019

I presume this has been resolved. If this is still an issue, please re-open.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quick Start - PM2
Start an app. The simplest way to start, daemonize and monitor your application is by using this command line: $ pm2 start app ......
Read more >
Launching multiple instances of PostGraphile with PM2
A typical way to launch the PostGraphile with PM2 is as below: pm2 start --name "postgraphile" postgraphile -- --append-plugins ...
Read more >
pm2 - Fig.io
Name, Description. start, Starts and daemonizes an app. trigger, Deploy your json. deploy, Deploy your json. startOrRestart, Start or restart JSON file.
Read more >
node.js - How to pass execution arguments to app using PM2?
11 Answers 11 · pm2 start app.js -- dev --port=1234 (note there is an extra space between -- and dev) · pm2 start...
Read more >
PM2 — Log Handling - Future Studio
PM2 has a module system that allow to extend the default with custom functionality. And there's a plugin for logrotate integration to PM2:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found