Reputation: 2248
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!
Upvotes: 39
Views: 68529
Reputation: 1187
Unable to run node app.js file
I came to this question in a very basic scenario. I was missing to mention an end point (response) and the browser was forever loading.
I fixed it with providing a response.
app.use ((req, res, next) => {
res.send('Hello World');
});
Upvotes: 0
Reputation: 21
the answer to this problem is simple ...... first save your file .... by command CMD + S
and then type - node app.js in terminal
Upvotes: 2
Reputation: 321
I had similar problem, I found that the problem was in a library called bcrypt,once i removed that library everything worked fine. So try to comment out the libraries you are using in app.js one by one and you will get to know which one is causing problem
Upvotes: 0
Reputation: 571
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");
});
Upvotes: 13
Reputation: 1328
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
Upvotes: 92
Reputation: 5553
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.
Upvotes: 2