I just started to learn about Express 4.0 in my Node.js app, and I found that it generated ./bin/www
file, on which only the application server and port settings are written and everything others like middleware and routing is defined in ./app.js
file.
However, I'm not sure what this ./bin/www
does. I've used Express 3.x and I have always defined server and port settings as well as routing and middleware on the identical ./app.js
file, and launched my node app with node app.js
. So what's the point of using the ./bin/www
? Does it only separate the server and port definition from others?
Right now, when I create the package using express-generator, the package.json
includes the following definition:
"scripts": {
"start": "node ./bin/www"
}
However, I wonder whether I should launch my app using node ./bin/www
, or npm start
. Which command should I run to start my app?
And also, when I deploy my app to heroku, what should I write in the Procfile
file? Is web: node app.js
enough?
/bin/www
is specific to theexpress-generator
tool. From the express docs: "Neither thebin
directory nor the extensionlesswww
file is mandatory for creating an Express app or starting the app." – Summit