Express Node.js doesn't work
Solution 1
The new express-generator does not add the app.listen
statement in the auto-generated app.js file. It could be a bug? What you can do is add a statement like
app.listen(3000, function () {
console.log("express has started on port 3000");
});
This will instruct express to listen on port 3000 and print out a helpful message on the console as well.
Solution 2
Auto generated express apps are not supposed to be started by running node app.js
.
If you look in your package.json
file, you should see something like
"scripts": {
"start": "node ./bin/www"
}
This is how the auto-generated app is designed to be started. You can start it either by running exactly what it says there (i.e. node ./bin/www"
from the root directory of your project), or the more proper way is to start it using npm start
from the root directory.
Abhishek Mhatre
Updated on September 15, 2022Comments
-
Abhishek Mhatre almost 2 years
I installed express 4 along with node.js,npm and express-generator on my ubuntu 12.04 and created an app using the following commands:
express test --hogan -c less cd test && npm install node app.js
Now what I should get is "Express server running on port 3000" but instead the command simply executes and doesn't leave any message or error. So I have no idea of which port express is running on or whether or not it is running at all. So does anyone know what's going wrong in it? Thanks in advance.
-
conor909 about 8 yearsI'm getting the correct log in the console, but my browser is hanging when I try to visit localhost:3000 - any ideas?
-
Zeyad Shaban over 3 yearsEither because you don't have a route handler or because you didn't return any response. app.get('/any_url', (req, res) => res.send('something to end the infinite event loop connection'))