Default Node.js + Express.js does not run
Asked Answered
U

3

16

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.

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.

I also tried to debug the application using node debug app, with the following results:

< 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.

What am I missing here?

Upheave answered 6/3, 2014 at 5:14 Comment(0)
W
43

Looks like the way to start app has changed. Instead of node app you should now do

npm start

More details here https://github.com/expressjs/generator

Wyeth answered 6/3, 2014 at 5:45 Comment(1)
Wow over a year later and the getting started docs are still out of date!Cidevant
Z
0

Certain node.js apps may try to daemonize or fork themselves when you start them.

For example, haraka uses the npm daemon module. 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.

For example, with haraka set a breakpoint here:

server.js:

  53 Server.daemonize = function () {
->54     var c = this.cfg.main;
  55     if (!c.daemonize) return;

then:

  1. Type repl in the debug> console
  2. Type this.cfg.main.daemonize = false
  3. Press Ctrl+c once to exit repl
  4. Continue debugging...
Zurkow answered 30/7, 2015 at 22:42 Comment(0)
L
0

I think it might be a bit late to answer the question still adding app.listen() enables the app to be started directly by node app.js

app.listen(port, function(){ console.log("Starting on port:",port) } )

Lucius answered 11/3, 2016 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.