2014-09-20 77 views
1

我是NodeJS的新手,我试着从express和express-generator开始。我已经安装了快车使用以下命令:'npm start'with Express-Generator(NodeJS)

C:\project>npm install -g express 

然后我安装了快车发生器模块:

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

然后我创建一个文件夹的项目和安装德的依赖关系:

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

一切工作正常,但当我尝试启动服务器时出现问题,使用命令:

C:\project\nodetest1>npm start 

看来,服务启动,但因为它即开始关闭,结果是:

> [email protected] start C:\project\nodetest1 
> node ./bin/www 

C:\project\nodetest1> 

当我尝试打开本地主机:3000这是行不通的。我在网上搜索,我还没有找到解决方案,有人可以指导我如何解决这个问题?

谢谢。

更新1:

有重新安装的node.js并遵循以下建议的步骤后,现在我得到一个错误:

C:\wamp\www\mynewapp>npm start 

> [email protected] start C:\wamp\www\mynewapp 
> node ./bin/www 


npm ERR! [email protected] start: `node ./bin/www` 
npm ERR! spawn ENOENT 
npm ERR! 
npm ERR! Failed at the [email protected] 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! [email protected] start: `node ./bin/www` 
npm ERR! Exit status -1 
npm ERR! 
npm ERR! Failed at the [email protected] 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> 
+0

你有没有经历过“Thinkster.io”角度教程? – Goodword 2015-02-26 16:11:04

+0

作为一个巧合,我昨天发现该网站,这个问题没有链接到该网站的任何教程。格式化PC后,我解决了这个问题,我从来不知道为什么会这样。 – Naschtok 2015-02-27 16:54:56

回答

1

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

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

的app.js应该已经由发电机产生,但考虑到你所描述的步骤,似乎你忘了生成应用程序。试试这个:

express mynewapp 
cd mynewapp 
npm install 
npm start 
+0

谢谢!但是现在我得到一个错误。我在我原来的帖子中发布了错误。 – Naschtok 2014-09-21 20:55:54

+0

'npm install'成功了吗? – fmsf 2014-09-22 07:01:49

+0

是的,它的确如此。但'npm start'会抛出该错误。 – Naschtok 2014-09-22 12:02:51

0

你可以很容易地解决这个问题。进入 “packages.json” 文件,然后更改开始

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

}

,并使其“开始”: “节点app.js”。然后运行命令npm start并且该项目不起作用。现在回到开始再次到“开始”:“节点./bin/www”这是Express中的默认值并运行命令,npm start。它为我工作。