Unable to run node app.js file
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.
Shivam
Self taught Front end developer. Looking to learn and hopefully help others too!
Updated on April 15, 2022Comments
-
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 about 10 yearsReally? I get an error that points me to: goo.gl/YnK8p0
-
Ethan Mick about 10 yearsAnd 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 commandhttp.createServer(app).listen(app.get('port'), function(){});
should not end the process - is that present? -
Shivam about 10 yearsOk I will remove that and try again i am using this tutorial.
-
Shivam about 10 yearsStill not working for me...
-
Brad about 10 years
node -v
gives you what exactly? -
Swanidhi over 9 yearsYou should use
node start
-
-
BananaBuisness over 7 yearsCan someone explain why it works and what is the purpose of it?
-
BananaBuisness over 7 yearsActually, node command is part of node-legacy package that you can download using apt...
-
Adrian Grzywaczewski about 7 yearsgreat answer. npm start did all the work for me. cheers @user626818
-
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 almost 6 yearswhat if i don't have a bin/www dir
-
Henry about 4 yearsUse 'yarn start' if you use yarn.
-
miltonbhowmick over 2 yearsIt 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: [] }