javascript - working - node.js hello world command line




Unable to run node app.js file (4)

I am learning node.js and I am trying to run the app.js file using the command node app.js but the bash returns nothing (no errors either). Here are the steps I followed:

$ brew install node

$ sudo npm install -g express

$ sudo npm install -g express-generator

after i get into a new folder I created I run

$ express testsite --hogan -c less

$ cd testsite && npm install

Finally

$ node app.js // returns no errors but nothing back except new command line...

Any help on this would be great.

Thanks!


Add app.listen(3000); to your app.js file.


After running...

express testsite --hogan -c less

I get the following message:

install dependencies:
  $ cd testsite && npm install

run the app:
  $ DEBUG=test ./bin/www

node app.js did not work for me either, but ./bin/www does.

FYI npm start also works for me. This basically runs ./bin/www.

EDIT: Was curious why node.app doesn't work, because I followed the same video guide. In the comments, someone said node changed their app start process since video was made.


You have to add this code to app.js file, this will tell express to listen on port 3000 and display a log message

 app.listen(3000, function () {
console.log("Express server listening on port 3000");
});

try npm start from testsite directory.

look at the package.json

scripts : { start : node bin/www }

So you must execute the www under the bin directory.

So instead of node app.js use node bin/www





bash