I have a python application which I am deploying through Flask using the render_template()
function onto a webpage. At the same time, I am trying to use npm to incorporate some javascript modules into my code. Whilst I have correctly installed the needed modules within the static
folder with all my other javascript files, the code refuses to recognize these modules.
My Flask CLI shows that my local development server has correctly located the module file but if I run var module = require('module')
the code shows no indication of having worked if run through the browser. This goes for whether I include this script inside my html template in the template
folder, or an external javascript file in the static
folder.
Interestingly enough, if I run the same external javascript file through the npm CLI using node script.js
, the script will execute. Can someone explain what I'm doing wrong and why this is so? I'm completely new to node.js, npm and have just started today so any help would be appreciated.
I am currently basing my work off of the answer with 6 upvotes here: How can I serve NPM packages using Flask?