The people running the company were playing with fire and they must either be too junior themselves to understand that, or they were just knowingly doing so and hoping to get whatever product MVP they had planned as quickly as possible with the minimum amount of expenses possible.
Don't feel bad for being fired from such a company. It might have been the best thing to happen to you because now you get the opportunity of getting a proper job where you might actually have experienced people to mentor you and help you become a great developer and professional.
With that said: next time a CTO asks you to create something in a month for a demo, just go ahead and implement a mock (no DB, no error handling, just happy path code) that's just about enough for the demo, nothing else. Make it clear to the person who is going to run the demo that this is not the real deal, and arrange for only the happy path to be followed in the demo (add a few safeguards just in case so if the person does something unexpected you just ignore it, never crash!). You could have probably pulled that off in a couple of days :D but yeah, you probably thought you needed to have the real final product ready otherwise it wouldn't be demo-able... Trust me, that's almost certainly not the case.