' npm start'使用Express-Generator(NodeJS)

时间:2014-09-20 08:43:26

标签: node.js express npm express-generator

我是NodeJS的新手,我正在尝试使用快速和快速生成器。我已经使用命令安装了express:

C:\project>npm install -g express

然后我安装了快速发电机模块:

C:\project>npm install -g express-generator

然后我为项目创建一个文件夹并安装de dependencies:

C:\project\express> nodetest1
C:\project\nodetest1>npm install

那里的一切正常,但是当我尝试使用以下命令启动服务器时出现问题:

C:\project\nodetest1>npm start

似乎服务启动但是一旦启动它就会关闭,结果:

> nodetest1@0.0.0 start C:\project\nodetest1
> node ./bin/www

C:\project\nodetest1>

当我尝试打开 localhost:3000 时,它不起作用。我在网上搜索,我还没有找到解决方案,有人可以指导我如何解决这个问题吗?

谢谢。

更新1:

重新安装node.js并按照下面提出的步骤后,现在出现错误:

C:\wamp\www\mynewapp>npm start

> mynewapp@0.0.0 start C:\wamp\www\mynewapp
> node ./bin/www


npm ERR! mynewapp@0.0.0 start: `node ./bin/www`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the mynewapp@0.0.0 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! mynewapp@0.0.0 start: `node ./bin/www`
npm ERR! Exit status -1
npm ERR!
npm ERR! Failed at the mynewapp@0.0.0 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>

3 个答案:

答案 0 :(得分:1)

你需要检查你的package.json npm start正在做什么。它应该有启动你的应用程序的命令,它应该有一个看起来像这样的部分:

"scripts": {
    "start": "node app.js"
},

app.js应该由生成器创建,但是根据您描述的步骤,您似乎忘记生成应用程序。试试这个:

express mynewapp
cd mynewapp
npm install
npm start

答案 1 :(得分:1)

您可以轻松解决此问题。转到" packages.json"文件然后更改开始

"scripts": {
"start": "node ./bin/www"

}

并使其"开始":"节点app.js" 。然后运行命令 npm start ,项目无法运行。现在返回并再次将开始更改为" start":" node ./bin/www" 这是默认值快速并运行命令, npm start。它对我有用。

答案 2 :(得分:1)

尝试http://www.npmjs.com/package/gennode,这是用于Node.js项目的非常简单的代码生成器模块。杂物控制器,路线,测试和文档将自动为您生成。因此,您只需要专注于使服务器独特的功能即可。