How to add a file in root directory of a flask app such that it can be accessed on localhost:5000/file?
It won't work like that, your app.py is running the server, so though it can access the js file, it would have to be on a route to shown. I would suggest you bring the js code to .html file in the  tags and then return render_template on this @app.route('/') .  This should display the html page whenever you visit 127.0.0.1:5000/ and run the JavaScript consequently.
I want to upload a js file in the root directory of my flask application such that I can access it on the url localhost:5000/file.js
I tried to put the js file on the same directory as app.py, but that didn't work.