Here comes the problem, you’re prototyping a website that has powerful front-end like EmberJS or AngularJS, and sync JSON data with your NodeJS back-end, but you want your nodejs code to be lite and clean.
You can use some nodeJS framework like restify, expressJS, director or whatever, but is there a way to write a minimal router using regex and switch statements? Yes.
The solution is pretty simple. JS switch statement can accept expressions as comparison keys, so simply do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
This may not as consistent as other heavy routers, but it’s really suitable for prototyping a new web app. Have fun and use it to hack your new weekend project!