Using frappe library in templates folder

I’m trying to create dynamic pages for my website
and I’m trying to use frappe library in js files but without any success
because I need to use and other frappe methods

for example, like this code but in my own app,

js is returning that frappe is undefined !

So is there a way to declare the frappe library in the templates folder or if not available in the public/js folder

also I tried to use jquery ajax call but the server is returning Error 500

Any Suggestions ?
Thank you all