Question

How to render statis file in nodejs if modules a re of type ES

Posted October 26, 2021 102 views
Node.jsAPI

In my project of node.js which is a ES module(as I have used “type”: “module” in package.JSON file) I am trying to render HTML file and image file which is stored in a “public” folder. When I am using app.use(express.static(‘public’)) and app.get('index.html’,{root:__dirname}). I am getting error

Error: __dirname is not defined

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!