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

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

问题描述

我是nodejs的新手。



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

  require(appdynamics)。profile 
controllerHostName:'< controller host name>',
controllerPort:< controller port number> ;,
controllerSslEnabled:false,//如果controllerPort是SSL,设置为true
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 应用程序的条目文件。详细信息:


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


  2. <






    b

    我唯一关心的是:



    如果 package.json 有类似于 {start :coffee server.coffee} ,我的脚本将它替换为 {start:coffee appdynamics.js} 。然后我的脚本会调用 npm start ,这将错误。



    什么是最好的解决方法?



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

    解决方案


    • 编写一个名为 appdynamics .coffee

    • 将此封装编译为 .js

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



    执行此操作后

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

    将为

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

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

    $ b b

    将是

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


    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

    解决方案

    • 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"
      }
    }
    

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

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