Question

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

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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer