Nodejs app with npm start script
- Write a wrapper called
appdynamics.coffee
- Compile this wrapper to
.js
- Replace
server.js
withappdynamics.js
andserver.coffee
withappdynamics.coffee
After this operations
{
"scripts": {
"start": "node server.js"
}
}
will be
{
"scripts": {
"start": "node appdynamics.js"
}
}
and
{
"scripts": {
"start": "coffee server.coffee"
}
}
will be
{
"scripts": {
"start": "coffee appdynamics.coffee"
}
}
user6147402
Updated on June 04, 2022Comments
-
user6147402 almost 2 years
I'm very new to nodejs.
In my dockerized environment, I want to provide appdynamics support to nodejs apps. This mandates every app to require the following as the first line in their app.
require("appdynamics").profile({ controllerHostName: '<controller host name>', controllerPort: <controller port number>, controllerSslEnabled: false, // Set to true if controllerPort is SSL accountName: '<AppDynamics_account_name>', accountAccessKey: '<AppDynamics_account_key>', //required applicationName: 'your_app_name', tierName: 'choose_a_tier_name', nodeName: 'choose_a_node_name', });
I plan to do that by providing a wrapper called appdynamics.js around the app's entry file. Details:
I run a script in my nodejs docker image to replace the entry file name in the app's package.json with "appdynamics.js", where appdynamics.js has the above appdynamics related require statement. Ex :
{scripts { "start" : "node server.js" }}
will be replaced with{scripts { "start" : "node appdynamics.js"}}
Then, i "require" the "server.js" inside appdynamics.js.
Invoke npm start.
My only concern is this:
If the package.json had something like scripts
{ "start" : "coffee server.coffee" }
, my script will replace it to{ "start" : "coffee appdynamics.js" }
. and then my script will invokenpm start
, which will error out.What is the best way to solve this?
This is a follow up question to Use "coffee" instead of "node" command in production