How to modify node-red deploy operation to save flow to database

Darshan, the function that is called when you press the deploy button lives in the runtime of node-red: this is server code, on nodejs. The code you have added to it uses jquery. Jquery is a framework for interacting with DOM structures in the browser, meaning it is clientside code.
If you want to do this, start by learning the difference between clientside and serverside, and learn some nodejs basics. Next, figure out a way to call http apis from nodejs.

The error you’re seeing is the call to the flows endpoint returning with a server error, status code 500 if I had to guess. You’re seeing that one in your browser because it is the response to a browser-made call, an XMLHttpRequest also known as XHR. You should also see the full error on the console/log where you run node-red.
The error you get “ReferenceError: is not defined” means that it has no clue what means so jquery is not available, which makes sense because you’re in the runtime. So it cannot make that call.