Nodejs应用程序与npm启动脚本 [英] Nodejs app with npm start script

查看:292
本文介绍了Nodejs应用程序与npm启动脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对nodejs非常新鲜。

I'm very new to nodejs.

在我的dockerized环境中,我想为nodejs应用程序提供appdynamics支持。这要求每个应用程序需要以下内容作为应用程序的第一行。

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', 
 });

我打算通过提供名为 appdynamics.js 的包装器该应用程序的输入文件。详细信息:

I plan to do that by providing a wrapper called appdynamics.js around the app's entry file. Details:


  1. 我在我的nodejs docker图像中运行一个脚本,以将应用程序的package.json中的条目文件名替换为 appdynamics.js,其中appdynamics.js具有上述appdynamics相关的require语句。
    例如: {scripts {start:node server.js}} 将替换为
    {scripts {start:node appdynamics.js}}

然后,我需要server.js在Appdynamics.js中。

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

调用npm开始。

我唯一关心的是:

如果 package.json 具有脚本 {开始:coffee server.coffee} ,我的脚本会将其替换为 {start:coffee appdynamics.js} 。然后我的脚本将调用 npm start ,这将会出错。

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?

这是一个后续问题,使用咖啡而不是节点命令生产

推荐答案


  • 编写一个名为 appdynamics的包装器.coffee

  • 将此包装编译为 .js

  • server.js 替换为 appdynamics.js server.coffee appdynamics.coffee

    • Write a wrapper called appdynamics.coffee
    • Compile this wrapper to .js
    • Replace server.js with appdynamics.js and server.coffee with appdynamics.coffee
    • 此操作后

      {
        "scripts": {
          "start": "node server.js"
        }
      }
      

      {
        "scripts": {
          "start": "node appdynamics.js"
        }
      }
      

      and

      {
        "scripts": {
          "start": "coffee server.coffee"
        }
      }
      

      {
        "scripts": {
          "start": "coffee appdynamics.coffee"
        }
      }
      

      这篇关于Nodejs应用程序与npm启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆