javascript - Migrating from asp.mvc application to node.js application with a focus on design -
i looking alternative platforms migrate existing application onto, started out prototype using asp.mvc majority of code javascript simple asp mvc web service looking @ taking forward seems sensible scrap current microsoft stack , go nodejs giving more freedom of , how host our application, can reuse of models , code in both web service , front end, although end being small amount.
this quite large question encompassing many parts put out there anyway sure helpful lots of other people looking @ how can move .net/java to node.js. of these statically typed languages have lots of patterns , practices used, such inversion of control, unit of work, aspect oriented programming etc seems bit strange moving towards platform doesn't seem require structure in area... have concerns migrating super structured , tested world new seemingly unstructured , dynamic world.
so here main things in mvc , want in node.js not quite sure best way achieve same level of separation or functionality.
routing actions
this mechanism in asp mvc seems replaceable express in node.js, give me same ability map route method. there couple of concerns:
in asp mvc controllers can dependency injected , have variables actions easy test depend on can mocked when needed , passed in via constructor. method in express seems not have containing scope seems have either use global variables or new variables internally. there nice way access business logic containers in these routed methods?
is there way autobind model being sent? or @ least json/xml etc in useful manner? appears if send on correct mime type content can extracted have not seen clear examples of online. happy use additional frameworks on top of express provide functionality, ideally want make post request
/user/1
, have user object pulled out , update user id 1 in database (which talk shortly).what best way validate data being sent over? in our front end javascript application use knockoutjs , models use knockout observables , validated using knockout.validation. happy use knockout validation on node models contract between front end , end, if there better solution happy go it.
database interactions
currently in .net land use nhibernate communicating our relational databases , mongodb driver communicating our mongodb databases. use generic repository pattern , isolate queries own classes. use unit of work pattern quite heavily can wrap logical chunks of word transaction , either commit if goes or roll if doesn't. gives ability mock out our objects @ level depending on want test , lets change our implementations easily. here concern:
- sequalize seems fit replacing nhibernate, doesn't seem have sort of transaction handling making difficult make unit of work pattern. not end of world if cannot done in same way, way of being able group chunk of work in way, action createnewuserunitofwork take model representing users details, validate it, create entry in 1 table, create relational data in others etc, users id database , send (assuming went well). looking @ querychainer seems provides of functionality if failed on 3rd of 5 actions doesn't appear simple roll back, there way level of control?
plugins / scattered configuration data
this more of niche concern of our application, have central application other dlls contain plugins. there dropped bin folder , hooked in routing, database , validation configuration. imagine having google homepage, , google maps, docs etc plugins told main application route additional calls methods within plugin, had own models , database configurations etc. here concern around this:
- there seems way update routing scanning directory new plugins , including them (node.js require files in folder?) there best practice around doing sort of thing don't want each requestto have directory scans. safe assume happy have plugins in right places @ time of starting node application no need add plugins @ runtime @ moment.
testing
currently there unit, integration, acceptance testing within application. unit tests happen on both front end , end, javascript tests using jstestdriver in our build script confirm business logic works intended in isolation etc. have integration tests done in c# test our controllers , actions work expected units of work etc, again kicked off build script can run via resharper unit test runner. have acceptance tests written in c# using web driver target front end , test functionality via browser. main concerns around are:
what best practice , frameworks testing nodejs? of tests test @ asp layer carried out via c# scripts creating controller mocked dependencies , running actions prove works intended using mvc helpers etc. wondering level of support nodejs has around this, doesn't seem simple (on quick glance) test node.js components without having node running.
assuming there way test node.js can hooked build scripts via command line runners etc? want automated , isolated wherever possible.
i appreciate more 5+ smaller questions rolled 1 bigger question underlying question how achieve design large node js application hoping still useful lot of people myself come larger enterprise applications node js style apps.
i recently switched asp mvc node.js , highly recommend switching.
i can't give information you're looking for, highly recommend sequelize orm , mocha (with expect.js , sinon) tests. sequelize adding transaction support in next version, 1.7.0. don't querychainer since each of it's elements executed separately.
i got frustrated jasmine test framework, missing afterall method shutting down express server after acceptance tests. mocha developed author of express.
if want have express server load in plugins, use singleton pattern this: https://github.com/jeydotc/articles/blob/master/express%20with%20sequelize.md
you https://github.com/visionmedia/express-resource provides restful interface accessing models. validation, think you'll happy https://github.com/ctavan/express-validator
why need test node modules without using node? it's considered standard call test script makefile, , can add pre-commit hook git run tests before making commit.
Comments
Post a Comment