A Simple MVC Setup In Node.JS

文章来源:http://www.travisglines.com/

 

I’m sure many of you have heard about the new server side javascript project called node.js. I’ve been using myself to build full stack dynamic websites and find it a very nice environment to create a dynamic website. When I first started out I had no idea what sort of way one should create an MVC style framework with node or what modules would help me to achieve the model, view, controller ideal. Heres my stack:

  • Node.js (http://nodejs.org/ ) of course
  • NPM (http://npmjs.org/ ) to easily install packages for node.
  • Express (http://expressjs.com/ ) – a very nice web development framework built on connect (allows “controllers”)
  • Mongoose (http://mongoosejs.com/ ) – a solid orm for mongodb in node.js that just released a much improved version (allows “models”)
  • Jade (http://jade-lang.com/ ) – a template engine for node that allows some cool shorthand (allows “views”)
  • Other tools were used of course but those were the essentials.

The application directory looks something like this:


Inside the application I instantiate express, include my mongoose models and include my routes/controllers from the controllers directory at the bottom. Inside the controllers I call res.render to render the jade views and it all works very nicely. If people would like me to elaborate on this more let me know.

A huge shoutout and thank you to the LearnBoost guys (TJ Holowaychuk, Guillermo Rauch, Aaron Heckmann, and many more that aren’t associated with LearnBoost) who’ve made Node.js web application development a breeze.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值