Category Archives: express

Modulize your website project —Build a node.js website from beginner – part3

You could write all your code inside the sever.js file, but this is not looking very nice and the node.js supports your to write very function to modules that will be easy maintain and to test it.

Especially in this day, we need write anything in MVC architecture way. Now we are going to creates a foleder named controllers in your project so here is the folder looks like.

nodejsWebsite04

now you have very nice and clear code in serve.js

Because I am not fan with jade, so vash engine is let you write html code like this @model.title

The index.js under the controllers file init your controllers.

nodejsWebsite06

here is your homeController.js file, get,post,delete,… wirte in this file

nodejsWebsite07

the last step is write your view, here is the layout.vash and index.vash

nodejsWebsite08

nodejsWebsite09

Then finally, go to local host will render page:

nodejsWebsite10

Advertisements