我是 NodeJS 的新手,我正在尝试从express和express-generator开始。我已经使用以下命令安装了express:
C:\project>npm install -g express
然后我安装了express-generator模块:
C:\project>npm install -g express-generator
然后我为项目创建一个文件夹并安装依赖项:
C:\project\express> nodetest1
C:\project\nodetest1>npm install
那里一切正常,但是当我尝试使用以下命令启动服务器时出现问题:
C:\project\nodetest1>npm start
看起来服务启动了但是一启动就关闭了,结果:
> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7816171c1d0c1d0b0c49384856485648" rel="noreferrer noopener nofollow">[email protected]</a> start C:\project\nodetest1
> node ./bin/www
C:\project\nodetest1>
当我尝试打开localhost:3000时,它不起作用。我在网上搜索过,但没有找到解决方案,有人可以指导我如何解决这个问题吗?
谢谢。
更新1:
重新安装 node.js 并按照下面建议的步骤操作后,现在出现错误:
C:\wamp\www\mynewapp>npm start
> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc918592998b9d8c8cbcccd2ccd2cc" rel="noreferrer noopener nofollow">[email protected]</a> start C:\wamp\www\mynewapp
> node ./bin/www
npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="96fbeff8f3e1f7e6e6d6a6b8a6b8a6" rel="noreferrer noopener nofollow">[email protected]</a> start: `node ./bin/www`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e4899d8a8193859494a4d4cad4cad4" rel="noreferrer noopener nofollow">[email protected]</a> start script.
npm ERR! This is most likely a problem with the mynewapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls mynewapp
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\wamp\www\mynewapp
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! syscall spawn
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93feeafdf6e4f2e3e3d3a3bda3bda3" rel="noreferrer noopener nofollow">[email protected]</a> start: `node ./bin/www`
npm ERR! Exit status -1
npm ERR!
npm ERR! Failed at the <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b5d8ccdbd0c2d4c5c5f5859b859b85" rel="noreferrer noopener nofollow">[email protected]</a> start script.
npm ERR! This is most likely a problem with the mynewapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls mynewapp
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\wamp\www\mynewapp
npm ERR! node -v v0.10.32
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! C:\wamp\www\mynewapp\npm-debug.log
npm ERR! not ok code 0
C:\wamp\www\mynewapp>
最佳答案
你可以轻松解决这个问题。转到“packages.json”文件,然后更改 start :
"scripts": {
"start": "node ./bin/www"
}
并将其设为"start": "node app.js"。然后运行命令npm start,该项目将无法运行。现在返回并再次将 start 更改为 "start": "node ./bin/www" (这是 Express 中的默认值)并运行命令 npm开始。它对我有用。
关于node.js - “npm start”与 Express-Generator (NodeJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25946947/