Example mvc in express

Example: create web mvc with express framework

Install express-mvc-generator:


C:\Nodejs>npm install express-mvc-generator –g


Create myapp by express:


C:\Nodejs>express myapp


   create : myapp

   create : myapp/public/js/script.js

   create : myapp/package.json

   create : myapp/app.js

   create : myapp/public/js

   create : myapp/public

   create : myapp/config

   create : myapp/config/routes.js

   create : myapp/config/constants.js

   create : myapp/config/database.js

   create : myapp/config/passport.js

   create : myapp/config/auth.js

   create : myapp/public/img

   create : myapp/lib

   create : myapp/lib/email.js

   create : myapp/public/css

   create : myapp/public/css/style.css

   create : myapp/app/views

   create : myapp/app/views/login.ejs

   create : myapp/app/views/signup.ejs

   create : myapp/app/views/index.ejs

   create : myapp/app/views/index.ejs

   create : myapp/app/views/error.ejs

   create : myapp/app/views/404.ejs


   install dependencies:

     > cd myapp && npm install


   run the app:

     > SET DEBUG=myapp:* & node app or nodemon app


   create : myapp/app/models

   create : myapp/app/models/home.js

   create : myapp/app/controllers

   create : myapp/app/controllers/home.js


Run myapp:


C:\Nodejs>cd myapp

C:\Nodejs\myapp>node app.js


    throw err;



Error: Cannot find module 'passport'

    at Function.Module._resolveFilename (module.js:470:15)

    at Function.Module._load (module.js:418:25)

    at Module.require (module.js:498:17)

    at require (internal/module.js:20:19)

    at Object.<anonymous> (C:\Nodejs \myapp\app.js:11:16)

    at Module._compile (module.js:571:32)

    at Object.Module._extensions..js (module.js:580:10)

    at Module.load (module.js:488:32)

    at tryModuleLoad (module.js:447:12)

    at Function.Module._load (module.js:439:3)

    at Module.runMain (module.js:605:10)

    at run (bootstrap_node.js:427:7)

    at startup (bootstrap_node.js:151:9)

    at bootstrap_node.js:542:3


You need install modules when start app.js :


C:\Nodejs\myapp>npm install passport

[email protected] C:\Nodejs\myapp

`-- [email protected]

  +-- [email protected]

  `-- [email protected]


Run app.js:


C:\Nodejs\myapp>node app.js

The magic happens on port 8042

(node:11672) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoNetworkError: failed to connect to server [] on first connect [MongoNetworkError: connect ECONNREFUSED]

(node:11672) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Error cause no mongodb but web still start

Go browser http://localhost:8042