Open sam-github opened 7 years ago
we already have a version of this with "node_hc" although how much its used I don't know.
The neat thing about this would be that you could autostart from a local install, so you could do
npm i --save appmetrics
export NODE_OPTIONS="-r appmetrics/start" # Requires nodejs/node#12028
npm start
and you'd have appmetrics working without having to globally install it, so it'd be portable.
Thinking about it though, it's probably more useful for appmetrics-dash. Does that already work? Can you do node -r appmetrics-dash/monitor test.js
or node -r appmetrics-dash/attach test.js
?
node_hc
is a different use-case.
With a requireable entrypoint I could (soon) do NODE_OPTIONS="-r /my/appmetrics/start" npm start
in a Dockerfile, node_hc requires rewriting the package.json for the app.
So this would need a new javascript file called 'start.js' or 'autostart.js' and then -r appmetrics/start
or -r appmetrics/autostart
would cause that file to be invoked. New file would simply need to require appmetrics and call start on it.
No reason why we couldn't do this for appmetrics-dash too, there are valid use cases for both.
It should be possible to both require appmetrics, and cause
.monitor()
to be called with a one-shot from the node command line. Perhapsnode -r appmetrics/start
?This will interact well with https://github.com/nodejs/node/pull/12028 when it lands, and be consistent with https://github.com/nodejs/node-report#usage (though node-report privileges the
-r
use-case by having the main require auto-start, and making people usenode-report/api
to get the API with no auto-starting, which is OK, different use-case).cc: @rnchamberlain @mhdawson