Unable to run node app.js file

52,664

Solution 1

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

Solution 2

Try running nodejs app.js instead of node app.js

Solution 3

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");
});

Solution 4

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.

Share:
52,664
Shivam
Author by

Shivam

Self taught Front end developer. Looking to learn and hopefully help others too!

Updated on April 15, 2022

Comments

  • Shivam
    Shivam about 2 years

    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!

    • Ethan Mick
      Ethan Mick about 10 years
      Really? I get an error that points me to: goo.gl/YnK8p0
    • Ethan Mick
      Ethan Mick about 10 years
      And after I fix that error (commenting out less, who needs that?!), I run it with node app.js and it works fine. Express server listening on port 3001. The command http.createServer(app).listen(app.get('port'), function(){}); should not end the process - is that present?
    • Shivam
      Shivam about 10 years
      Ok I will remove that and try again i am using this tutorial.
    • Shivam
      Shivam about 10 years
      Still not working for me...
    • Brad
      Brad about 10 years
      node -v gives you what exactly?
    • Swanidhi
      Swanidhi over 9 years
      You should use node start
  • BananaBuisness
    BananaBuisness over 7 years
    Can someone explain why it works and what is the purpose of it?
  • BananaBuisness
    BananaBuisness over 7 years
    Actually, node command is part of node-legacy package that you can download using apt...
  • Adrian Grzywaczewski
    Adrian Grzywaczewski about 7 years
    great answer. npm start did all the work for me. cheers @user626818
  • George
    George over 6 years
    @Pikamander2 nodejs is used on ubuntu instead of node, can't remember why or if it's the same on other linux flavours.
  • Janac Meena
    Janac Meena almost 6 years
    what if i don't have a bin/www dir
  • Henry
    Henry about 4 years
    Use 'yarn start' if you use yarn.
  • miltonbhowmick
    miltonbhowmick over 2 years
    It does not working for me. It gives an error below, Error: Cannot find module 'I:\Property inspection\Video-Call-App-NodeJS\src\bin\www' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15) at Function.Module._load (internal/modules/cjs/loader.js:745:27) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] }