【问题标题】:Debug is not a recognized command (express)调试不是一个公认的命令(表达)
【发布时间】:2014-12-03 10:13:27
【问题描述】:

我在 Windows 8 上运行 express。我运行了命令

>express app

在我运行命令安装依赖项之后

>cd app && npm install

在我尝试使用给定命令运行应用程序之后

>DEBUG=my-application ./bin/www

但我收到了错误消息

'Debug' is not recognized as an internal or external command,
operable program or batch file.

关于如何解决这个问题的任何想法? 一些背景信息,我从他们的网站成功安装了 node.js。我尝试使用命令安装 express

>npm install

当这不起作用时,我按照本网站https://coderwall.com/p/mbov6w 上的说明进行操作。当那不起作用时,我使用了以下命令并且它起作用了

npm install -g express-generator@3

我还根据 express 网站制作了自己的 package.json 和 app.js,现在我被卡住了。

【问题讨论】:

标签: node.js express windows-8.1


【解决方案1】:

首先,您必须将 DEBUG 设置为环境变量:

set DEBUG=my-application

然后,您可以运行应用程序:

node bin/www

【讨论】:

    【解决方案2】:

    对于 Windows,请按照以下步骤操作:

    1. 转到您的应用程序,即 cd app
    2. npm 安装
    3. 设置 DEBUG=app
    4. npm 开始

    默认会开始监听 3000 端口。

    【讨论】:

      【解决方案3】:

      在项目的根文件夹中,您必须运行此命令

      对于 Windows:

      set DEBUG=express:* & node bin/www
      

      【讨论】:

        【解决方案4】:

        对于 Windows:将 package.json 文件中的启动命令更改为

        "scripts": {
            "start": "set DEBUG=my-application & node ./bin/www"   
        }
        

        然后你可以运行 npm start。 不需要先在你的cmd窗口中设置DEBUG环境变量。

        【讨论】:

          【解决方案5】:

          例如,对于 windows 环境,您需要使用 SET VARIABLE

          "scripts" : {
             "start" : "SET DEBUG=app & node ./bin/www"
          }
          

          这将帮助您使用 windows 环境,但如果您想使用跨平台,我建议安装此库 cross-env 该库将帮助您为 windows 和 linux 环境设置变量。 json 应该是这样的:

          "scripts" : {
              "start" : "cross-env DEBUG=app & node ./bin/www"
          }
          

          我遇到了同样的问题,这对我有帮助!

          【讨论】:

            【解决方案6】:

            这解决了我的问题:

                "scripts": {
                "test": "echo \"Error: no test specified\" && exit 1",
                "start": "node src/index.js"
              }
            

            【讨论】:

              【解决方案7】:

              在您的 package.json 上使用此设置

              对于窗口用户..

                "scripts": {
                  "test": "echo \"Error: no test specified\" && exit 1",
                  "start": "set DEBUG=app & node app.js"
                },
              

              对于 Mac 用户

                "scripts": {
                  "test": "echo \"Error: no test specified\" && exit 1",
                  "start": "DEBUG=app node app.js"
                },
              

              app 是您的应用名称,例如 [app.js][server.js] 等。

              【讨论】:

                【解决方案8】:

                以下命令适用于使用 nodemon 在 Git Bash 上运行的 windows 用户。

                "scripts": {
                "start": "node index.js",
                "dev": "SET DEBUG=app:* & nodemon index.js"
                }
                

                【讨论】:

                  猜你喜欢
                  • 2013-03-07
                  • 1970-01-01
                  • 2011-05-19
                  • 1970-01-01
                  • 2014-09-16
                  • 1970-01-01
                  • 1970-01-01
                  • 2017-04-22
                  • 1970-01-01
                  相关资源
                  最近更新 更多