【问题标题】:'nodejs' is not recognized as an internal or external command'nodejs' 未被识别为内部或外部命令
【发布时间】:2016-11-10 07:01:54
【问题描述】:

我正在使用 Express 创建一个 Node.js 应用程序。通常,要在本地运行应用程序,我输入node app.js,一切正常。但是,现在我正在使用一本书来学习如何创建快速应用程序,它要求我创建一个 bin/www 文件,其中包含以下内容:

#!/usr/bin/nodejs
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

这本书还要求我安装 nodemon 来运行应用程序。但是,每次我使用npm startnodemon 启动应用程序时,都会出现错误:

'nodejs' 未被识别为内部或外部命令

环境变量设置正确,我已经仔细检查过。

这里是调试日志:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start' ]
2 info using npm@2.15.8
3 info using node@v4.4.7
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info prestart application-name@0.0.1
6 info start application-name@0.0.1
7 verbose unsafe-perm in lifecycle true
8 info application-name@0.0.1 Failed to exec start script
9 verbose stack Error: application-name@0.0.1 start: `nodejs ./bin/www`
9 verbose stack Exit status 1
9 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:217:16)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at EventEmitter.emit (events.js:172:7)
9 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
9 verbose stack     at emitTwo (events.js:87:13)
9 verbose stack     at ChildProcess.emit (events.js:172:7)
9 verbose stack     at maybeClose (internal/child_process.js:827:16)
9 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid application-name@0.0.1
11 verbose cwd C:\Users\Humad\Dropbox\projects\loc8r
12 error Windows_NT 10.0.14393
13 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
14 error node v4.4.7
15 error npm  v2.15.8
16 error code ELIFECYCLE
17 error application-name@0.0.1 start: `nodejs ./bin/www`
17 error Exit status 1
18 error Failed at the application-name@0.0.1 start script 'nodejs ./bin/www'.
18 error This is most likely a problem with the application-name package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error     nodejs ./bin/www
18 error You can get information on how to open an issue for this project with:
18 error     npm bugs application-name
18 error Or if that isn't available, you can get their info via:
18 error
18 error     npm owner ls application-name
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]

【问题讨论】:

  • 将您的start 命令更改为使用node,而不是nodejs

标签: node.js express


【解决方案1】:

您似乎已经知道(通过输入 node app.js),Windows 上的 Node 进程是 node,而不是 nodejs

将 package.json 中的 start 命令更改为正确的命令。

【讨论】:

    猜你喜欢
    • 2019-02-02
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2013-10-11
    • 2013-01-25
    • 2016-10-01
    • 2022-01-22
    相关资源
    最近更新 更多