【问题标题】:How to run an Express app with powershell如何使用 powershell 运行 Express 应用程序
【发布时间】:2017-06-25 01:24:00
【问题描述】:

我想使用 Powershell 运行 ExpressJS 应用程序。当我使用SET DEBUG=myApp:* & npm start 时,它与 cmd 一起工作,但它在 powershell 中不起作用。错误信息如下:

At line:1 char:24
+ SET DEBUG=helloworld:* & npm start
+                        ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.
    + CategoryInfo: ParserError: (:) [],ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed  

我曾尝试消除 & 符号或将其包含在引号中,但无济于事;我不断收到更多错误消息。我用谷歌搜索了这个,但没有找到答案。

我想知道在 powershell 中使用什么命令来运行我的 ExpressJS 应用程序。

通过使用其他用户建议的一些其他命令,我收到以下错误:

PS C:\Users\User\myNode\helloworld> [Environment]::SetEnvironmentVariable("DEBUG","helloworld:"‌​); &npm 开始 在行:1 字符:61 + [环境]::SetEnvironmentVariable("DEBUG","helloworld:"‌​); &np ... + ~ 方法调用中缺少 ')'。 在行:1 字符:61 + ... Environment]::SetEnvironmentVariable("DEBUG","helloworld:"‌​); &npm ... + ~~ 表达式或语句中出现意外的标记“‌​”。 在行:1 字符:63 + ... nvironment]::SetEnvironmentVariable("DEBUG","helloworld:"‌​); &npm ... + ~ 表达式或语句中出现意外的标记 ')'。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

PS C:\Users\User\myNode\helloworld> [Environment]::SetEnvironmentVariable("DEBUG","helloworld:* & npm start") PS C:\Users\User\myNode\helloworld>

【问题讨论】:

  • $env:DEBUG='helloword:*'; npm start
  • 谢谢,但我仍然收到该命令的错误
  • 你能展示更多你的代码以及你在哪里使用Debug吗?没有看到更多,我们正在猜测您要做什么。其中之一可能是您正在寻找的:[Environment]::SetEnvironmentVariable("DEBUG","helloworld:*"); & npm start[Environment]::SetEnvironmentVariable("DEBUG","helloworld:* & npm start")
  • 我已经编辑了我的问题,包括我使用得到的错误:
  • [环境]::SetEnvironmentVariable("DEBUG","helloworld:*"‌​); & npm 开始

标签: node.js powershell express


【解决方案1】:

PS C:\Users\hp\Desktop\myapp> 设置 DEBUG='myapp:*'; npm 开始

【讨论】:

    【解决方案2】:

    以下内容对我使用 powershell 非常有用。

    PS > [Environment]::SetEnvironmentVariable("DEBUG","express:*"); & npm start
    
    > <hidden_data>@0.0.0 start C:\<hidden_data>
    > node ./bin/www
    
      express:router:route new '/' +0ms
      express:router:layer new '/' +0ms
      express:router:route get '/' +15ms
      express:router:layer new '/' +0ms
      express:router:route new '/' +0ms
      express:router:layer new '/' +0ms
      express:router:route get '/' +0ms
      express:router:layer new '/' +0ms
      express:application set "x-powered-by" to true +0ms
      express:application set "etag" to 'weak' +0ms
      express:application set "etag fn" to [Function: generateETag] +0ms
      express:application set "env" to 'development' +0ms
      express:application set "query parser" to 'extended' +0ms
      express:application set "query parser fn" to [Function: parseExtendedQueryString] +0ms
      express:application set "subdomain offset" to 2 +16ms
      express:application set "trust proxy" to false +0ms
      express:application set "trust proxy fn" to [Function: trustNone] +0ms
      express:application booting in development mode +3ms
      express:application set "view" to [Function: View] +1ms
      ...
      <hidden_data>
      ...
      express:application set "jsonp callback name" to 'callback' +1ms
      express:application set "views" to 'C:\\1d\\MaterialDesignComponentsPjs\\ExpressAppGeneratorPjs\\pioneer-towers-res-assoc-sass\\views' +1ms
      express:application set "view engine" to 'pug' +1ms
      express:router use '/' query +2ms
      express:router:layer new '/' +0ms
      express:router use '/' expressInit +1ms
      express:router:layer new '/' +1ms
      express:router use '/' logger +1ms
      express:router:layer new '/' +0ms
      express:router use '/' jsonParser +2ms
      express:router:layer new '/' +1ms
      express:router use '/' urlencodedParser +1ms
      express:router:layer new '/' +1ms
      express:router use '/' cookieParser +1ms
      express:router:layer new '/' +1ms
      express:router use '/' sass +2ms
      express:router:layer new '/' +1ms
      express:router use '/' serveStatic +1ms
      express:router:layer new '/' +0ms
      express:router use '/' router +1ms
      express:router:layer new '/' +1ms
      express:router use '/users' router +0ms
      express:router:layer new '/users' +1ms
      express:router use '/' <anonymous> +0ms
      express:router:layer new '/' +1ms
      express:router use '/' <anonymous> +0ms
      express:router:layer new '/' +1ms
      express:application set "port" to 3000 +1ms
      express:router dispatching GET / +29s
      express:router query  : / +4ms
      express:router expressInit  : / +2ms
      express:router logger  : / +1ms
      express:router jsonParser  : / +5ms
      express:router urlencodedParser  : / +1ms
      express:router cookieParser  : / +1ms
      express:router sass  : / +1ms
      express:router serveStatic  : / +6ms
      express:router router  : / +5ms
      express:router dispatching GET / +1ms
      express:view require "pug" +2ms
      express:view lookup "index.pug" +680ms
      <hidden_data>
    GET / 304 782.513 ms - -
    

    【讨论】:

      【解决方案3】:

      在 MacOS 或 Linux 上,使用以下命令运行应用程序:

      $ DEBUG=myapp:* npm start
      

      在 Windows 命令提示符下,使用以下命令:

      > set DEBUG=myapp:* & npm start
      

      在 Windows PowerShell 上,使用以下命令:

      PS> $env:DEBUG='myapp:*'; npm start
      

      【讨论】:

        【解决方案4】:

        遇到了同样的问题,把-&-改成-'找到了解决办法;

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-09-13
          • 2017-11-15
          • 2018-02-23
          • 1970-01-01
          • 2015-08-28
          • 2015-06-29
          相关资源
          最近更新 更多