0

I was following along to this tutorial about setting up an express app. But when I ran node app.js the server would not start. The previous command that I ran was

cd express_example && npm install

But I got this error

npm WARN engine express@4.9.8: wanted: {"node":">= 0.10.0"} (current: {"node":"0.8.4","npm":"2.1.4"})
npm WARN engine void-elements@1.0.0: wanted: {"node":">=0.10.0"} (current: {"node":"0.8.4","npm":"2.1.4"})

So i thought that it was because a newer version of node was necessary. So I looked at the version of node that I had, noticed it was older so I tried upgrading. But when I ran brew update node i got this alert.

Error: node-0.10.32 already installed

I did some searching around and found this answer here on SO. Which suggested running these commands

sudo npm cache clean -f

then

sudo npm install -g n

then

sudo n stable

But the server still wont startup. But at least I am now at v0.10.33

I also found this similar question on SO whose accepted answer said to try sudo node app.js but that just does not seem right, nor did it even work.

Community
  • 1
  • 1
JGallardo
  • 11,074
  • 10
  • 82
  • 96
  • you shouldn't have had problems i just did it, try to do something like this `sudo npm install -g express-generator` – ariel_556 Nov 15 '14 at 20:28
  • What is the error when starting the server? – Brendan Nov 16 '14 at 00:28
  • @BrendanAshworth There is no error, it simply does not start when in the terminal I entered `node app.js` – JGallardo Dec 10 '14 at 00:16
  • @JGallardo what is the response code if you get no response from the command? (`echo $?`) If it is 0, it may not have binded correctly. – Brendan Dec 10 '14 at 03:44

1 Answers1

2

If you are using Express 4 and using the generator, there is a slightly diffrent method for running the app. Express 4 changed the file structure to:

├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

Notice the bin/www directory.

The app start logic is now seperated in the bin/www file. Therefore you have to run your app with the following command:

DEBUG=<<app_name>> ./bin/www

Reference: http://expressjs.com/starter/generator.html

Farhan Ahmad
  • 5,148
  • 6
  • 40
  • 69
  • I don't know if it has again changed but your command does not work. It says that DEBUG is not a recognized command. Instead it suggest SET DEBUG=app_name & npm start but again the & is not recognized so you should do those separatedly – KansaiRobot Dec 03 '18 at 08:46