I've seen tutorials for express.js such as this which starts from scratch with their own app.js
file and forgoes using the express generator.
My question: for beginner who's trying to grasp just how to use these tools and make a basic web application should I be concerned with bin/www
or should I just be defining the port within app.js
?
The only functionality I currently understand in bin/www
is setting the port. Is the express generator simply bloated with edge case functionality which is too much for a beginner?
"scripts": { "start": "node ./bin/www" }, This is the code that allows you to run npm start for the app.
The bin/ directory serves as a location where you can define your various startup scripts. The www is an example to start the express app as a web server.
No, It isn't, ExpressJs is framework build on top of nodejs, as they are many framework in different programming language it is the same for Javascript in the backend side. In the nodejs world ExpressJS is the popular one, so in many books it's normal to talk about It, as Javascript was firstly build for the web.
Here is the reason, stated succinctly by an express maintainer:
So you can require('./app') from external files and get the express app that is not listening on any port (think unit tests and the like).
source
app.js
www
var server = http.createServer(app);
server.listen(port);
server.on('error', onError);
Explanation so, basically it removes all the create and start server code from your app.js and let you focus only on the application logic part. Note: If you see in package.json
file you would note this:
"scripts": { "start": "node ./bin/www" }
this means if you type in terminal npm start
then it will automatically start the ./bin/www
file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With