2

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:

  1. 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"}}

  2. Then, i "require" the "server.js" inside appdynamics.js.

  3. 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 invoke npm 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

Community
  • 1
  • 1
user6147402
  • 21
  • 1
  • 1
  • 4
  • Why would you not do this as part of a build process that simply injects the relevant code into your server.js file? You could use any templating engine, regex replace, etc. Grunt, gulp, make, whatever. – Jared Smith Jul 27 '16 at 16:04
  • Thanks for taking time to respond. The reason is because I'm on the PAAS team and only we know the values of the fields required by appdynamics. Also, we want to make appdynamics seamlessly available to the nodejs apps running on our platform. That way, the app developer needn't worry about the appdynamics configuration values. – user6147402 Jul 27 '16 at 22:40
  • That makes total sense then. Doing this seamlessly will likely be difficult. – Jared Smith Jul 28 '16 at 14:48

1 Answers1

4
  • Write a wrapper called appdynamics.coffee
  • Compile this wrapper to .js
  • Replace server.js with appdynamics.js and server.coffee with appdynamics.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"
  }
}
Tomasz Jakub Rup
  • 10,502
  • 7
  • 48
  • 49