Search code examples
node.jsexpressexpress-generator

Using expressjs and express-generator, where in bin/www does it call app.js?


I followed the installation for express-generator properly I think. I see in the package.json that the starting script is bin/www. I looked through bin/www and can't find where that script calls my script 'app.js'.


Solution

  • When you run npm start, it reads package.json file and execute start in scripts tag.

    "scripts": {
       "start": "node ./bin/www"
    },
    

    So, it executes node ./bin/www in which you must have var app = require('../app'); which loads the app.js dependency.

    And following lines creates the http server from app.js and start listening at given port

    var server = http.createServer(app);
    server.listen(port);
    

    Disclaimer: Above observation is based on default express myapp app.