I am new to Node.js 6 and Express 4. I am wondering if something like this is possible todo? It appears wildcards can be used in the routeing of node. Is it possible to have a database driven app that is dynamic with routes and views? What I mean is something like the following URL's
- / <- can be anything
- /xyz
- /15/abc/xyz
So node/express would hit the database for the URL of / and then dynamically take the values in the row for / lookup it found, and output the path to the view template page with the SQL query ready to be used in the view template file that is local on disk. I know their is no way to dynamically generate the html because the SQL will be different for each view template URL. So that would haft to be a hard file with template engine like handlebars, etc. It appears node/express can dynamically deal with routes on the fly so this should be possible todo I think.
So when node/express get the URL of /xyz it will go into the database look up the URL and then output the SQL in the lookup row and call the path to the view template for that row it found in the database. Database could be a json file not sql too. Do not know what would be faster since both would be in RAM.
I am wondering if anyone has ever tried this? If they have dose anything like this or dose anyone know of a boilerplate with this kind of a setup on github? I can see several problems.
- Handling 404 errors
- Database pools, Ways to reduce the open and closing sockets. So when 100 URL requests would not have a 1,000 open and close socket requests. It would have just 1 open socket request and do all the SQL via that socket. Or have 64 sockets for 64 cpu system. Not open and closing socket every time you hit the URL.
- Run app under PM2 Clustering so it will use all the CPU's not just one CPU.
I would like any input. How you would over come the problems listed or boilerplate to something like this if it is out their already?