[英]Default Node.js + Express.js does not run
I am trying to learn to create web apps with nodejs
and expressjs
, following the getting started guide found at the expressjs website , under the heading Using express(1) to generate an app . 我正在尝试学习使用
nodejs
和expressjs
创建web应用程序,遵循在expressjs网站上的使用快递(1)生成应用程序标题下的入门指南。
I generated an app using the express-generator
plugin, ran npm install
, and then attempted to run the application by using node app
(I also tried node app.js
for good measure. When running either of these commands, there is no output to the terminal whatsoever. 我使用
express-generator
插件生成了一个应用程序,运行npm install
,然后尝试使用node app
运行应用node app
(我也尝试了node app.js
以便进行测量。当运行这些命令时,没有输出到终端无论如何。
I also tried to debug the application using node debug app
, with the following results: 我还尝试使用
node debug app
程序node debug app
,结果如下:
< debugger listening on port 5858
connecting... ok
break in app.js:1
1 var express = require('express');
2 var http = require('http');
3 var path = require('path');
debug> cont
program terminated
debug> cont
App isn't running... Try `run` instead
debug>
I did find a file bin/www
that seemed to contain the code to start the server, and, sure enough, running node bin/www
succeeded in starting the application. 我确实找到了一个文件
bin/www
,似乎包含启动服务器的代码,而且,运行node bin/www
确实成功启动了应用程序。
What am I missing here? 我在这里错过了什么?
Looks like the way to start app has changed. 看起来启动应用的方式已经改变。 Instead of
node app
you should now do 你现在应该做的不是
node app
npm start
More details here https://github.com/expressjs/generator 更多细节请访问https://github.com/expressjs/generator
Certain node.js
apps may try to daemonize or fork themselves when you start them. 某些
node.js
应用程序可能会在您启动它们时尝试进行守护或分叉。
For example, haraka
uses the npm daemon
module. 例如,
haraka
使用npm daemon
模块。 In order to avoid the original process exiting, you will usually have to either disable daemon mode in the app, or try to use the debugger repl
to bypass the part of the code that daemonizes. 为了避免原始进程退出,您通常必须在应用程序中禁用守护程序模式,或者尝试使用调试器
repl
绕过守护程序的代码部分。
For example, with haraka
set a breakpoint here : 例如,
haraka
在这里设置了一个断点:
server.js:
53 Server.daemonize = function () {
->54 var c = this.cfg.main;
55 if (!c.daemonize) return;
then: 然后:
repl
in the debug>
console debug>
console中键入repl
this.cfg.main.daemonize = false
this.cfg.main.daemonize = false
Ctrl+c
once to exit repl
Ctrl+c
一次退出repl
我认为回答这个问题可能有点晚了仍然添加app.listen()
使应用程序可以由node app.js
直接启动
app.listen(port, function(){ console.log("Starting on port:",port) } )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.