structure - Working with Node.JS -
last night dump windows 7 , formatted hard driver port linux based operating system, purely reasons wanted start working node.js
so have installed node.js , have done few test stuff, http server , sockets etc.
what build http server tightly intergrated mvc framework, before started on need learn how build efficiently in node.
for example within php framework create bootloading system load base classes etc, fire events system ready start attaching callbacks.
i continue process request etc until output generated gets sent of output handler process headers etc etc
but node s totally new environment , im wondering on best practises build system in node.
the information im looking more design structure rather actual coding of application, how load lib load libs, etc etc
any appreciated.
so far webapplication coming along nicely, have built application pretty traditionally , little procedural.
what have started out creating directory structure so:
<root> startup.js /public/ favicon.ico /images/ /stylesheets/ /javascripts/ /system/ init.js config.js /libs/ /exceptions/ http.js server.js /application/ /views/ /_override/ /errors/ generic.view /partials/ sidebar.voew index.view /controllers/ index.js /models/ users.js
this directory structure mvc based web applications out there using method feel comfortable.
the startup file whats executed node entry point, node startup &
, looks so:
/* * header of t file, copyright etc */ var _intitialize = require("./system/init.js"); //displays command line header, title, copyright etc _intitialize.displaycommandlineheader(); //check enviroment, permissions, ports etc _intitialize.checkenviroment(); //start server , listen port. _initialize.startserver();
the init file main work, tells other areas of system run, stop etc.
i have file in libs called serverhandler.js,
, required init.js, create server , assign callback serverhandler.listener
. listens requests, checks see if file exists in public directory, if reads in chunks , sends back.
if no file found in public create route route.create("/path?params"); deters 3 elements, controller, method, params uri, , controller files loaded if exists.
i've taken on approach of throwing error pages so:
if(!filesystem.exists(requiredpath)) { throw new httpexceptions.filenotfound(); }
hope helps people getting started in node.
have @ http://dailyjs.com/2010/11/01/node-tutorial/ , it's pretty relevant.
i suggest looking @ current modules https://github.com/joyent/node/wiki/modules , reading code of of projects in areas interested in, esp. middleware, routing , module loaders.
Comments
Post a Comment